[Vuejs]-How to download files on the browser

0👍

The problem is the method of handle the response in axios.I hope the code could help you

validateGrpc() {
   
    axios.post("http://127.0.0.1:8090/download", {
    data: this.url,
    responseType: 'blob'
  })
          .then(response => {
            var blob = new Blob([response.data]);
            var downloadElement = document.createElement("a");
            var href = window.URL.createObjectURL(blob); //create the download url
            downloadElement.href = href;
            downloadElement.download = "test.mp4"; //the name of the downloaded file
            document.body.appendChild(downloadElement);
            downloadElement.click(); //click to file
            document.body.removeChild(downloadElement); //remove the element 
            window.URL.revokeObjectURL(href); //release the object  of the blob

            //    console.log(response);
          })
          .catch(response => {
            console.log(response);
          });
    }, 

If you use my code to download the file ,you will see the file from the browser.
I have see your code on the github.I think you should put the video.mp4 into the directory vue-go-study\backend.Then everything goes well.

Leave a comment