如何在目录中保存 blob url 数据

How to save blob url data in a directory

我正在处理录音。现在我想把录制的音频直接保存在我们本地。当我录制音频时,它会返回 blob URL,例如:

blob:http://example.com/7737-4454545-545445

当我点击 URL 时,它会播放录制的音频。现在我将 blob URL 从 js 发送到 PHP 脚本以保存您的本地目录,但它不起作用。

我该怎么做?

Blob URL 生命周期链接到 document,它从 BlobFile 对象创建了 Blob URLBlob URL 无法 post 编辑到服务器作为存储在 snapshot state. See Blob URL StoreBlob 的参考。

您可以使用 fetch()Response.blob()Blob URL、post FormDataBlob 表示形式发送到服务器。

// `blobURL` : `"blob:http://example.com/7737-4454545-545445"`
fetch(blobUrl).then(response => response.blob())
.then(blob => { 
  const fd = new FormData();
  fd.append("fileName", blob, "file.ext"); // where `.ext` matches file `MIME` type  
  return fetch("/path/to/server", {method:"POST", body:fd})
})
.then(response => response.ok)
.then(res => console.log(res))
.catch(err => console.log(err));