Displaying Pdf from azure blob storage











up vote
2
down vote

favorite
1












I'm trying to get a pdf file displayed on my page. The pdf file is located as a blob on azure. I'm getting the link to the blob itself from the server, that way i can grab the file directly from the storage instead of passing it through the server.



I set up a shared access signature(SAS key) because the container is protected.



Since I'm using angular 5 I need to sanitize my url which i'm doing.



 this.http.get(baseUrl + 'api/download/fileuri?sheetId=' + this.sheetId, { responseType: 'text' }).subscribe(result => {
this.url = result.toString();
this.sanitizedUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.url);
console.log(this.sanitizedUrl);
}, error => console.error(error));


I'm then putting it inside a object, yet i either get nothing but a white page or i get the following error.



<object [data]="sanitizedUrl" type="application/pdf" style="width:100%; height:100vh"></object>


enter image description here



I set up the following in azure:



enter image description here



The weirdest part is: I can grab that file but just inputting that link, it just starts downloading it. But the moment i try to access it from the object, it throws that error. So the link is correct and it works. It's just whenever i try to access it from within the page..










share|improve this question




















  • 1




    You need to enable CORS for your blob
    – user184994
    Nov 8 at 11:25










  • I did, the last picture is of the storage account CORS. I allowed all traffic to go through by putting in * to make sure that would not block it for testing
    – SNIPEZ
    Nov 8 at 11:57















up vote
2
down vote

favorite
1












I'm trying to get a pdf file displayed on my page. The pdf file is located as a blob on azure. I'm getting the link to the blob itself from the server, that way i can grab the file directly from the storage instead of passing it through the server.



I set up a shared access signature(SAS key) because the container is protected.



Since I'm using angular 5 I need to sanitize my url which i'm doing.



 this.http.get(baseUrl + 'api/download/fileuri?sheetId=' + this.sheetId, { responseType: 'text' }).subscribe(result => {
this.url = result.toString();
this.sanitizedUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.url);
console.log(this.sanitizedUrl);
}, error => console.error(error));


I'm then putting it inside a object, yet i either get nothing but a white page or i get the following error.



<object [data]="sanitizedUrl" type="application/pdf" style="width:100%; height:100vh"></object>


enter image description here



I set up the following in azure:



enter image description here



The weirdest part is: I can grab that file but just inputting that link, it just starts downloading it. But the moment i try to access it from the object, it throws that error. So the link is correct and it works. It's just whenever i try to access it from within the page..










share|improve this question




















  • 1




    You need to enable CORS for your blob
    – user184994
    Nov 8 at 11:25










  • I did, the last picture is of the storage account CORS. I allowed all traffic to go through by putting in * to make sure that would not block it for testing
    – SNIPEZ
    Nov 8 at 11:57













up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






1





I'm trying to get a pdf file displayed on my page. The pdf file is located as a blob on azure. I'm getting the link to the blob itself from the server, that way i can grab the file directly from the storage instead of passing it through the server.



I set up a shared access signature(SAS key) because the container is protected.



Since I'm using angular 5 I need to sanitize my url which i'm doing.



 this.http.get(baseUrl + 'api/download/fileuri?sheetId=' + this.sheetId, { responseType: 'text' }).subscribe(result => {
this.url = result.toString();
this.sanitizedUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.url);
console.log(this.sanitizedUrl);
}, error => console.error(error));


I'm then putting it inside a object, yet i either get nothing but a white page or i get the following error.



<object [data]="sanitizedUrl" type="application/pdf" style="width:100%; height:100vh"></object>


enter image description here



I set up the following in azure:



enter image description here



The weirdest part is: I can grab that file but just inputting that link, it just starts downloading it. But the moment i try to access it from the object, it throws that error. So the link is correct and it works. It's just whenever i try to access it from within the page..










share|improve this question















I'm trying to get a pdf file displayed on my page. The pdf file is located as a blob on azure. I'm getting the link to the blob itself from the server, that way i can grab the file directly from the storage instead of passing it through the server.



I set up a shared access signature(SAS key) because the container is protected.



Since I'm using angular 5 I need to sanitize my url which i'm doing.



 this.http.get(baseUrl + 'api/download/fileuri?sheetId=' + this.sheetId, { responseType: 'text' }).subscribe(result => {
this.url = result.toString();
this.sanitizedUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.url);
console.log(this.sanitizedUrl);
}, error => console.error(error));


I'm then putting it inside a object, yet i either get nothing but a white page or i get the following error.



<object [data]="sanitizedUrl" type="application/pdf" style="width:100%; height:100vh"></object>


enter image description here



I set up the following in azure:



enter image description here



The weirdest part is: I can grab that file but just inputting that link, it just starts downloading it. But the moment i try to access it from the object, it throws that error. So the link is correct and it works. It's just whenever i try to access it from within the page..







angular azure azure-storage






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 13:09









Chamila Maddumage

122113




122113










asked Nov 8 at 11:23









SNIPEZ

345




345








  • 1




    You need to enable CORS for your blob
    – user184994
    Nov 8 at 11:25










  • I did, the last picture is of the storage account CORS. I allowed all traffic to go through by putting in * to make sure that would not block it for testing
    – SNIPEZ
    Nov 8 at 11:57














  • 1




    You need to enable CORS for your blob
    – user184994
    Nov 8 at 11:25










  • I did, the last picture is of the storage account CORS. I allowed all traffic to go through by putting in * to make sure that would not block it for testing
    – SNIPEZ
    Nov 8 at 11:57








1




1




You need to enable CORS for your blob
– user184994
Nov 8 at 11:25




You need to enable CORS for your blob
– user184994
Nov 8 at 11:25












I did, the last picture is of the storage account CORS. I allowed all traffic to go through by putting in * to make sure that would not block it for testing
– SNIPEZ
Nov 8 at 11:57




I did, the last picture is of the storage account CORS. I allowed all traffic to go through by putting in * to make sure that would not block it for testing
– SNIPEZ
Nov 8 at 11:57












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










I recommend you to download Microsoft Azure Storage Explorer. Inside of it you can set CORS policy for specific resource. I hope it will solve your problem.



enter image description here






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',
    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%2f53206761%2fdisplaying-pdf-from-azure-blob-storage%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








    up vote
    1
    down vote



    accepted










    I recommend you to download Microsoft Azure Storage Explorer. Inside of it you can set CORS policy for specific resource. I hope it will solve your problem.



    enter image description here






    share|improve this answer

























      up vote
      1
      down vote



      accepted










      I recommend you to download Microsoft Azure Storage Explorer. Inside of it you can set CORS policy for specific resource. I hope it will solve your problem.



      enter image description here






      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        I recommend you to download Microsoft Azure Storage Explorer. Inside of it you can set CORS policy for specific resource. I hope it will solve your problem.



        enter image description here






        share|improve this answer












        I recommend you to download Microsoft Azure Storage Explorer. Inside of it you can set CORS policy for specific resource. I hope it will solve your problem.



        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 8 at 11:59









        Mateusz Wyczawski

        513




        513






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f53206761%2fdisplaying-pdf-from-azure-blob-storage%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







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()