如何在目录中保存blob url数据 [英] How to save blob url data in a directory

查看:305
本文介绍了如何在目录中保存blob url数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working on the audio record. Now I want to save that recorded audio in our local directly. When I record audio it is returning blob URL like:

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

当我点击此URL时,它会播放录制的音频。现在我将jb中的blob URL发送到PHP脚本以保存本地目录,但它无法正常工作。

When I hit this URL it plays recorded audio. Now I am sending that blob URL from js to PHP script to save your local directory but it is not working.

我该怎么做?

推荐答案

Blob URL 生命周期链接到文档 Blob 文件对象创建了 Blob URL Blob URL 无法发布到服务器作为 Blob 的参考.github.io / FileAPI / #snapshot-staterel =nofollow noreferrer>快照状态。请参阅 Blob URL Store

Blob URL lifetime is linked to document which created Blob URL from Blob or File object. Blob URL cannot be posted to server as reference for a Blob stored at snapshot state. See Blob URL Store.

您可以使用 fetch() Response.blob()获取 Blob 表示 Blob URL ,发布 FormData 到服务器。

You can use fetch(), Response.blob() to get Blob representation of Blob URL, post FormData to server.

// `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));

这篇关于如何在目录中保存blob url数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆