Reputation: 1515
Is this possible in Angularjs? Googling has returned not many results, mostly for php and express. The reason why I want to do it client side is because I've already have the url in place, so i might as well do it there. Unless my approach is completely wrong, please enlighten me
Upvotes: 0
Views: 175
Reputation: 3385
It cant be done directly using Angular. We followed the below steps to achieve downloading of image.
Instead of accessing the image through URL directly, have a PHP page which serves the image by accepting image name.
Add download header to the PHP so that it will open save dialogue if you access the URL.
header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file));
eg.,
<a href="imageprovider.php?imgeurl" target"_blank">download</a>
will download the image.
Upvotes: 1