jaredad7
jaredad7

Reputation: 1058

How would I display an image from s3 on a webpage in my flask app without saving it?

I have an ec2 instance running a flask website, and I want to get a certain image from s3 only if a certain user is logged into the site and display it on the homepage. The image can be downloaded with cli tools on the ec2 instance, but I don't want to save it to the harddrive. I want to keep the direct link to the object in s3 private.

Basically, can I do something like what this user is doing, but instead pass the file into the template and display it?

Upvotes: 1

Views: 1085

Answers (1)

Vikyol
Vikyol

Reputation: 5625

CloudFront signed cookies can be used to serve private content. It is possible to prevent misuse of cookies by:

  • Encrypting the cookie
  • Using a custom policy and including the IP address of the viewer.
  • Specifying the shortest reasonable expiration time based on how long you want users to have access to your content.

Don't forget to create an Origin Access Identity (OAI) to give necessary permissions to Cloudfront to access the bucket.

Upvotes: 1

Related Questions