Apprentice Programmer
Apprentice Programmer

Reputation: 1515

Saving a image from a remote server to disk

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

Answers (1)

Subash Selvaraj
Subash Selvaraj

Reputation: 3385

It cant be done directly using Angular. We followed the below steps to achieve downloading of image.

  1. Instead of accessing the image through URL directly, have a PHP page which serves the image by accepting image name.

  2. 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

Related Questions