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












0















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.










share|improve this question

























  • 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


















0















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.










share|improve this question

























  • 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
















0












0








0








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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





















  • 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














1 Answer
1






active

oldest

votes


















0














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 }}"/>





share|improve this answer























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    0














    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 }}"/>





    share|improve this answer




























      0














      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 }}"/>





      share|improve this answer


























        0












        0








        0







        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 }}"/>





        share|improve this answer













        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 }}"/>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 5:17









        WhodiniWhodini

        50913




        50913






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini