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");

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.