javascript如何上传blob? [英] How can javascript upload a blob?
本文介绍了javascript如何上传blob?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Blob {type:audio / wav,size:655404, slice:function}
size:655404
type:audio / wav
__proto__:Blob
这实际上是使用最近的Chrome getUerMedia()
和 Recorder.js
如何使用jquery的post方法将此blob上传到服务器?我没试过就试过这个:
$ .post('http://localhost/upload.php',{ fname:test.wav,data:soundBlob},
function(responseText){
console.log(responseText);
});
解决方案
试试这个
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);
});
您需要使用 FormData API 并设置 jQuery.ajax
的 processData
和 contentType
到 false
。
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);
});
解决方案
Try this
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);
});
You need to use the FormData API and set the jQuery.ajax
's processData
and contentType
to false
.
这篇关于javascript如何上传blob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文