angularjs - Amazon s3 file download -
i working django rest framework / angularjs based web application. going use amazon s3 save images used in ui. 1 problem: want logged-in user access these images - hate direct accessing image files on s3 bucket via url this:
https://racerx-snap4that-media.s3.amazonaws.com/images/iphone6white-1.png
in other word - link should work authenticated user. there solution or protect policy this? please me.
there 2 relatively straight forward ways accomplish this.
using aws temporary security credentials
when authorised user loads website, generate temporary security credentials provides user access or of resources within bucket. during preflight stage of angular application make request api endpoint retrieves signature, , use throughout application, assuming have shared state somewhere.
serve file through django view
i wouldn't recommend this, might easier you. can load image via view this:
def get(self, request): if not request.user.is_authenticated: return httpresponseforbidden() return httpresponse(requests.get(your_aws_url), content_type="image/png")
the reason why not recommend this, because you'll make user wait images download twice. once while server downloading image, , again when user downloading image. hey, if need quick , dirty solution, it'll work.
Comments
Post a Comment