How to display media files stored in Amazon S3 in Django template?
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.
html django amazon-web-services amazon-s3
add a comment |
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.
html django amazon-web-services amazon-s3
Please see this answer: stackoverflow.com/questions/26604977/…
– Randall Hunt
Nov 15 '18 at 22:27
Possible duplicate of URL for public Amazon S3 bucket
– Randall Hunt
Nov 15 '18 at 22:28
@RandallHunt The question you link to helps somewhat, but mine is more about how to display it in a Django template.
– Whodini
Nov 15 '18 at 22:58
add a comment |
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.
html django amazon-web-services amazon-s3
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.
html django amazon-web-services amazon-s3
html django amazon-web-services amazon-s3
edited Nov 15 '18 at 23:01
Whodini
asked Nov 15 '18 at 22:20
WhodiniWhodini
50913
50913
Please see this answer: stackoverflow.com/questions/26604977/…
– Randall Hunt
Nov 15 '18 at 22:27
Possible duplicate of URL for public Amazon S3 bucket
– Randall Hunt
Nov 15 '18 at 22:28
@RandallHunt The question you link to helps somewhat, but mine is more about how to display it in a Django template.
– Whodini
Nov 15 '18 at 22:58
add a comment |
Please see this answer: stackoverflow.com/questions/26604977/…
– Randall Hunt
Nov 15 '18 at 22:27
Possible duplicate of URL for public Amazon S3 bucket
– Randall Hunt
Nov 15 '18 at 22:28
@RandallHunt The question you link to helps somewhat, but mine is more about how to display it in a Django template.
– Whodini
Nov 15 '18 at 22:58
Please see this answer: stackoverflow.com/questions/26604977/…
– Randall Hunt
Nov 15 '18 at 22:27
Please see this answer: stackoverflow.com/questions/26604977/…
– Randall Hunt
Nov 15 '18 at 22:27
Possible duplicate of URL for public Amazon S3 bucket
– Randall Hunt
Nov 15 '18 at 22:28
Possible duplicate of URL for public Amazon S3 bucket
– Randall Hunt
Nov 15 '18 at 22:28
@RandallHunt The question you link to helps somewhat, but mine is more about how to display it in a Django template.
– Whodini
Nov 15 '18 at 22:58
@RandallHunt The question you link to helps somewhat, but mine is more about how to display it in a Django template.
– Whodini
Nov 15 '18 at 22:58
add a comment |
1 Answer
1
active
oldest
votes
This answer can also be found at Getting MEDIA images on Amazon S3 server on template so if mods feel this is not needed feel free to delete.
Super simple. All you have to do is:
<img src="{{ model.file.url }}"/>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328695%2fhow-to-display-media-files-stored-in-amazon-s3-in-django-template%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This answer can also be found at Getting MEDIA images on Amazon S3 server on template so if mods feel this is not needed feel free to delete.
Super simple. All you have to do is:
<img src="{{ model.file.url }}"/>
add a comment |
This answer can also be found at Getting MEDIA images on Amazon S3 server on template so if mods feel this is not needed feel free to delete.
Super simple. All you have to do is:
<img src="{{ model.file.url }}"/>
add a comment |
This answer can also be found at Getting MEDIA images on Amazon S3 server on template so if mods feel this is not needed feel free to delete.
Super simple. All you have to do is:
<img src="{{ model.file.url }}"/>
This answer can also be found at Getting MEDIA images on Amazon S3 server on template so if mods feel this is not needed feel free to delete.
Super simple. All you have to do is:
<img src="{{ model.file.url }}"/>
answered Nov 16 '18 at 5:17
WhodiniWhodini
50913
50913
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328695%2fhow-to-display-media-files-stored-in-amazon-s3-in-django-template%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please see this answer: stackoverflow.com/questions/26604977/…
– Randall Hunt
Nov 15 '18 at 22:27
Possible duplicate of URL for public Amazon S3 bucket
– Randall Hunt
Nov 15 '18 at 22:28
@RandallHunt The question you link to helps somewhat, but mine is more about how to display it in a Django template.
– Whodini
Nov 15 '18 at 22:58