How to display media files stored in Amazon S3 in Django template?

Viewed 4150

I have integrated Amazon S3 with my Django app. A media folder has been created in my S3 bucket, and when users upload a file it shows up there just fine. What I'm unclear about is how to display these files in the template. Currently the code is:

<img src="https://s3.console.aws.amazon.com/s3/buckets/myprojectbucket/media/{{ model.file }}"/>

I've also tried:

<img src="{{ model.file }}"/>

Another thing to keep in mind is when I try to access these files from the S3 account I get this output. Not sure if this is a permissions issue or what. However, in the admin the image shows up fine.

  • No longer getting access denied-I made access public (Not sure if this is the only/best way to do it). Still unclear on how to display it in template. The url gives a 404 error.

  • In Admin the file path is /folder/file.jpg, but in the template the file path is /media/folder/file.jpg. I think this could be the source of the problem, but not sure why media is there.

Any help would be appreciated.

1 Answers
Related