C# File Download no response in the frontend and have to click on the network name to fire the response

Viewed 23

I had created a app with frontend in vue.js and use axios to request backend (asp.net core) to get the file from azure blob and download them to the client side. But the download got no response in the frontend. Until I press on F12 and go into the network and double click on the Name of the response then the file was started to download. How to solve to let it auto download the file in the frontend

F12 network page

Frontend

this.$axios
.get(process.env.API.EQUIPMENT_OTHER_DOWNLOADZIP + '?' + queries)
.then((response) => {
   console.log(response)
})

Backend

public async Task<ActionResult> GetZipFile(string fileValue, string fileName)
{
  byte[] result = this.equipmentCSVLinkService.GetZipFile(fileValue);
  return this.File(result, MediaTypeNames.Application.Zip, fileName + ".zip");

}
1 Answers

Use document.location.href = response.request.responseURL

this.$axios
        .get(process.env.API.EQUIPMENT_OTHER_DOWNLOADZIP + '?' + queries)
        .then((response) => {
          // ZIPファイルをダウンロードする
          document.location.href = response.request.responseURL
        })
Related