0

I'm working on Angular 6 project and i need to download an image which hosted in AWS S3 (Remotely.I tried below approach and it didn't work for me .I have the image URL

<a href=" http://localhost/projectName/uploads/3/1535352341_download.png" class="btn clss"
                  target="_self" download>Download</a>
Chamila
  • 19
  • 2
  • Possible duplicate of [Force browser to download image files on click](https://stackoverflow.com/questions/17527713/force-browser-to-download-image-files-on-click) – Madhawa Priyashantha Nov 14 '19 at 07:55
  • seems like the above method will only work if you have the image placed in the assets folder – Joel Joseph Nov 14 '19 at 08:03
  • it seems download doesn't work for cross-origin hrefs as mentioned in this answer.https://stackoverflow.com/a/17527821/1886334 .so it's better to use another approach.may be it will work if you allow cross domain share not sure – Madhawa Priyashantha Nov 14 '19 at 08:03
  • Attach the stacktrace of errors which you are getting it is difficult to find it without knowing what are the cause of your problem instead of knowing your problem. – Himanshu Sharma Nov 14 '19 at 08:10
  • @HimanshuSharma there wont be any error it will just load the image in the same tab . the reason is as Madhawa Priyashantha stated above – Joel Joseph Nov 14 '19 at 08:14

1 Answers1

1

Here are a bunch of checks which you should do before trying to access an S3 Object publicly.

  1. Public access must be enabled on the S3 object.
  2. CORS must be allowed on the bucket.
  3. The object should open on the browser if you enter the link to the S3 Image.

The first and second checks can be done from the AWS S3 Console page itself.

If all these three tests pass, then it should work fine, in my opinion. Do reply if you face any errors! :)

Vedant Kashyap
  • 111
  • 1
  • 3
  • 12