How can javascript upload a blob?

html, javascript, jquery

Solution

You can use the FormData API.

If you're using `jquery.ajax`, you need to set `processData: false` and `contentType: false`.

var fd = new FormData();
fd.append('fname', 'test.wav');
fd.append('data', soundBlob);
$.ajax({
    type: 'POST',
    url: '/upload.php',
    data: fd,
    processData: false,
    contentType: false
}).done(function(data) {
       console.log(data);
});

Problem

I have a blob data in this structure: ``` Blob {type: "audio/wav", size: 655404, slice: function} size: 655404 type: "audio/wav" __proto__: Blob ``` It's actually sound data recorded using the recent Chrome `getUerMedia()` and Recorder.js How can I upload this blob to the server using jquery's post method? I've tried this without any luck: ``` $.post('http://localhost/upload.php', { fname: "test.wav", data: soundBlob }, function(responseText) { console.log(responseText); }); ```

Original source

Related problems