Vue2 getting image src












0















I have a function that gets images from an array



onFileChange(e) {
let files = e.target.files;
for (let file in files) {
this.files.push(URL.createObjectURL(files[file]));
if (files.hasOwnProperty(file)) {
console.log(files[file]);
}
}


Which is triggered by this element:



<input multiple type="file" @change="onFileChange($event)"/>


My data object for this component is:



data() {
return {
files: ,
url: null,
uploadedFiles:
}


When I render I get this error:




app.js:1920 Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.




I am actually getting the file array. but with this error, help appreciated.










share|improve this question





























    0















    I have a function that gets images from an array



    onFileChange(e) {
    let files = e.target.files;
    for (let file in files) {
    this.files.push(URL.createObjectURL(files[file]));
    if (files.hasOwnProperty(file)) {
    console.log(files[file]);
    }
    }


    Which is triggered by this element:



    <input multiple type="file" @change="onFileChange($event)"/>


    My data object for this component is:



    data() {
    return {
    files: ,
    url: null,
    uploadedFiles:
    }


    When I render I get this error:




    app.js:1920 Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.




    I am actually getting the file array. but with this error, help appreciated.










    share|improve this question



























      0












      0








      0








      I have a function that gets images from an array



      onFileChange(e) {
      let files = e.target.files;
      for (let file in files) {
      this.files.push(URL.createObjectURL(files[file]));
      if (files.hasOwnProperty(file)) {
      console.log(files[file]);
      }
      }


      Which is triggered by this element:



      <input multiple type="file" @change="onFileChange($event)"/>


      My data object for this component is:



      data() {
      return {
      files: ,
      url: null,
      uploadedFiles:
      }


      When I render I get this error:




      app.js:1920 Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.




      I am actually getting the file array. but with this error, help appreciated.










      share|improve this question
















      I have a function that gets images from an array



      onFileChange(e) {
      let files = e.target.files;
      for (let file in files) {
      this.files.push(URL.createObjectURL(files[file]));
      if (files.hasOwnProperty(file)) {
      console.log(files[file]);
      }
      }


      Which is triggered by this element:



      <input multiple type="file" @change="onFileChange($event)"/>


      My data object for this component is:



      data() {
      return {
      files: ,
      url: null,
      uploadedFiles:
      }


      When I render I get this error:




      app.js:1920 Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.




      I am actually getting the file array. but with this error, help appreciated.







      javascript vue.js vuejs2 filereader






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 31 '18 at 23:25









      Boussadjra Brahim

      8,1843733




      8,1843733










      asked Dec 31 '18 at 21:01









      clusterBuddyclusterBuddy

      626415




      626415
























          3 Answers
          3






          active

          oldest

          votes


















          1














          I think the problem is from this line this.files.push(URL.createObjectURL(files[file]));



          It should be this.files.push(window.URL.createObjectURL(files[file])); in case of {}.toString.apply(files[file]) === '[object Blob]'



          Otherwise,



          const binaryData = ;
          binaryData.push(files[file]);
          window.URL.createObjectURL(new Blob(binaryData, {type: "application/zip"}))


          Ref: Failed to execute 'createObjectURL'






          share|improve this answer































            0














            I still have no idea why this error occured yet i've found a workaround by switch from for/in to a regular "boring" for.



                            for (var i = 0; i < files.length; i++) {
            var file = files[i],
            src = (window.URL || window.webkitURL).createObjectURL(file);
            this.files.push(src);
            }


            If there'll be an answer that would explain the error, ill vote it as the answer, this this is the best solve found by now.






            share|improve this answer































              0














              I think your problem is not with for and for...in, it's with window.URL.

              After you used this:



              (window.URL || window.webkitURL).createObjectURL


              Instead of this (URL => window.URL):



              URL.createObjectURL


              It worked for you, it's a browser compatibility issue.






              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%2f53991390%2fvue2-getting-image-src%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                1














                I think the problem is from this line this.files.push(URL.createObjectURL(files[file]));



                It should be this.files.push(window.URL.createObjectURL(files[file])); in case of {}.toString.apply(files[file]) === '[object Blob]'



                Otherwise,



                const binaryData = ;
                binaryData.push(files[file]);
                window.URL.createObjectURL(new Blob(binaryData, {type: "application/zip"}))


                Ref: Failed to execute 'createObjectURL'






                share|improve this answer




























                  1














                  I think the problem is from this line this.files.push(URL.createObjectURL(files[file]));



                  It should be this.files.push(window.URL.createObjectURL(files[file])); in case of {}.toString.apply(files[file]) === '[object Blob]'



                  Otherwise,



                  const binaryData = ;
                  binaryData.push(files[file]);
                  window.URL.createObjectURL(new Blob(binaryData, {type: "application/zip"}))


                  Ref: Failed to execute 'createObjectURL'






                  share|improve this answer


























                    1












                    1








                    1







                    I think the problem is from this line this.files.push(URL.createObjectURL(files[file]));



                    It should be this.files.push(window.URL.createObjectURL(files[file])); in case of {}.toString.apply(files[file]) === '[object Blob]'



                    Otherwise,



                    const binaryData = ;
                    binaryData.push(files[file]);
                    window.URL.createObjectURL(new Blob(binaryData, {type: "application/zip"}))


                    Ref: Failed to execute 'createObjectURL'






                    share|improve this answer













                    I think the problem is from this line this.files.push(URL.createObjectURL(files[file]));



                    It should be this.files.push(window.URL.createObjectURL(files[file])); in case of {}.toString.apply(files[file]) === '[object Blob]'



                    Otherwise,



                    const binaryData = ;
                    binaryData.push(files[file]);
                    window.URL.createObjectURL(new Blob(binaryData, {type: "application/zip"}))


                    Ref: Failed to execute 'createObjectURL'







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 2 at 3:36









                    Hoang Tran SonHoang Tran Son

                    18719




                    18719

























                        0














                        I still have no idea why this error occured yet i've found a workaround by switch from for/in to a regular "boring" for.



                                        for (var i = 0; i < files.length; i++) {
                        var file = files[i],
                        src = (window.URL || window.webkitURL).createObjectURL(file);
                        this.files.push(src);
                        }


                        If there'll be an answer that would explain the error, ill vote it as the answer, this this is the best solve found by now.






                        share|improve this answer




























                          0














                          I still have no idea why this error occured yet i've found a workaround by switch from for/in to a regular "boring" for.



                                          for (var i = 0; i < files.length; i++) {
                          var file = files[i],
                          src = (window.URL || window.webkitURL).createObjectURL(file);
                          this.files.push(src);
                          }


                          If there'll be an answer that would explain the error, ill vote it as the answer, this this is the best solve found by now.






                          share|improve this answer


























                            0












                            0








                            0







                            I still have no idea why this error occured yet i've found a workaround by switch from for/in to a regular "boring" for.



                                            for (var i = 0; i < files.length; i++) {
                            var file = files[i],
                            src = (window.URL || window.webkitURL).createObjectURL(file);
                            this.files.push(src);
                            }


                            If there'll be an answer that would explain the error, ill vote it as the answer, this this is the best solve found by now.






                            share|improve this answer













                            I still have no idea why this error occured yet i've found a workaround by switch from for/in to a regular "boring" for.



                                            for (var i = 0; i < files.length; i++) {
                            var file = files[i],
                            src = (window.URL || window.webkitURL).createObjectURL(file);
                            this.files.push(src);
                            }


                            If there'll be an answer that would explain the error, ill vote it as the answer, this this is the best solve found by now.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Dec 31 '18 at 21:08









                            clusterBuddyclusterBuddy

                            626415




                            626415























                                0














                                I think your problem is not with for and for...in, it's with window.URL.

                                After you used this:



                                (window.URL || window.webkitURL).createObjectURL


                                Instead of this (URL => window.URL):



                                URL.createObjectURL


                                It worked for you, it's a browser compatibility issue.






                                share|improve this answer




























                                  0














                                  I think your problem is not with for and for...in, it's with window.URL.

                                  After you used this:



                                  (window.URL || window.webkitURL).createObjectURL


                                  Instead of this (URL => window.URL):



                                  URL.createObjectURL


                                  It worked for you, it's a browser compatibility issue.






                                  share|improve this answer


























                                    0












                                    0








                                    0







                                    I think your problem is not with for and for...in, it's with window.URL.

                                    After you used this:



                                    (window.URL || window.webkitURL).createObjectURL


                                    Instead of this (URL => window.URL):



                                    URL.createObjectURL


                                    It worked for you, it's a browser compatibility issue.






                                    share|improve this answer













                                    I think your problem is not with for and for...in, it's with window.URL.

                                    After you used this:



                                    (window.URL || window.webkitURL).createObjectURL


                                    Instead of this (URL => window.URL):



                                    URL.createObjectURL


                                    It worked for you, it's a browser compatibility issue.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Dec 31 '18 at 23:44









                                    DabbasDabbas

                                    1,60852858




                                    1,60852858






























                                        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%2f53991390%2fvue2-getting-image-src%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







                                        Popular posts from this blog

                                        MongoDB - Not Authorized To Execute Command

                                        in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

                                        How to fix TextFormField cause rebuild widget in Flutter