0

I have used this How to download files using axios.post from webapi (It could be duplicate of this) to work on this scenario but i am not getting success.

 React: 
   axios.post("URL",{data:data, responseType: "blob"})
  1. In response i am getting corrupted data, not bytes.
  2. ResponseType works with get request but why not with post?

WebAPI Core: return File(arraybytes, "application/vnd.openxmlformats- officedocument.spreadsheetml.sheet", "test.xlsx");

Sandeep Rasgotra
  • 582
  • 1
  • 7
  • 18

1 Answers1

2

Here is how I could be able to download videos that are hosted on S3 AWS buckets,

const handleDownload = () => {
    const link = document.createElement("a");
    link.target = "_blank";
    link.download = "YOUR_FILE_NAME"
    axios
      .get(url, {
        responseType: "blob",
      })
      .then((res) => {
        link.href = URL.createObjectURL(
          new Blob([res.data], { type: "video/mp4" })
        );
        link.click();
      });
  };

And I trigger handleDownload function in a button with onClick.

The url in the function has the video URL from S3 buckets