1

我正在使用下面的代码来下载剪辑。我已成功收到回复,我正在尝试下载视频,但我无法下载。

const completeUrl = url + "/getClip";

const res = await client.post(completeUrl, params, {
          headers: {
            "Content-Type": "video/mp4",
            "X-Amz-Target": "CodeBuild_20161006.StartBuild",
          },
        });
    
console.log("axios signedRquest is ", res);


   var binaryData: any = [];
        binaryData.push(res.data);

        const downloadElement = document.createElement("a");
        const href = window.URL.createObjectURL(
          new Blob(binaryData, { type: contentType })
        );
        downloadElement.href = href;
        downloadElement.download = "test.mp4";
        document.body.appendChild(downloadElement);
        downloadElement.click();
        document.body.removeChild(downloadElement);
        window.URL.revokeObjectURL(href);
4

1 回答 1

0

我只需 responseType: "blob" 在请求中添加即可找到解决方案

const res = await client.post(completeUrl, params, {
          headers: {
            "Content-Type": "video/mp4",
            "X-Amz-Target": "CodeBuild_20161006.StartBuild",
          },
          responseType: "blob", // added this line
        });
于 2021-12-22T17:19:58.513 回答