admin管理员组

文章数量:1333210

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: .

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.

How can I do that?

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./7737-4454545-545445.

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.

How can I do that?

Share Improve this question edited May 5, 2017 at 5:43 Vikrant 5,04618 gold badges51 silver badges75 bronze badges asked May 2, 2017 at 4:24 RAC BRAC B 411 silver badge8 bronze badges 1
  • It's not helpful if you don't post your code and tell us exactly what is not working(JavaScript not sending?php not receiving?file not saving? Saved but not readable?) – Nick Li Commented May 2, 2017 at 4:28
Add a ment  | 

1 Answer 1

Reset to default 6

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.

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

// `blobURL` : `"blob:http://example./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));

本文标签: javascriptHow to save blob url data in a directoryStack Overflow