我正在使用https://github.com/cwilso/AudioRecorder,除了获取 blob 并将其发送到服务器之外,一切正常。我有以下将表单数据发送到服务器。基本上,在客户端生成一个 wav 文件,然后将其存储在一个 blob 中,我想找出一种获取该 blob 内容的方法。
$('#submit').click(function(){
var formData = new FormData($('#add_slide').get(0));
var jContent = $( "#main_container" );
//console.log(formData);
if($('#audio_file').val().length==0)
{
var blob_url = $('#blob_url').val();
if($('#blob_url').val().length==0)
{
alert('Recording Could not be found. Please try again');
return false;
}else{
console.log(formData);
}
//return false;
}else{
var ext = $('#audio_file').val().split('.').pop().toLowerCase();
if(ext!== 'wav') {
alert('Invalid File. Please use a file with extension WAV!');
return false;
}
}
$.ajax({
url: 'lec_add_slide.php', //server script to process data
type: 'POST',
xhr: function() { // custom xhr
myXhr = $.ajaxSettings.xhr();
if(myXhr.upload){ // check if upload property exists
myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // for handling the progress of the upload
//console.log('OK');
}else{
//console.log('NOT');
}
return myXhr;
},
//Ajax events
beforeSend: function (){
$('#loadingModal').modal('show');
},
success: function (data) {
jContent.html( data );
$('#loadingModal').modal('hide');
},
error: function (){
console.log('error');
},
// Form data
data: formData,
//Options to tell JQuery not to process data or worry about content-type
cache: false,
contentType: false,
processData: false
});
});
function progressHandlingFunction(e){
if(e.lengthComputable){
$('#bar-progress-mp3').css('width',((e.loaded/e.total)*100)+'%');
}
}
如果我使用常规文件输入发送常规文件,则一切正常。我已将 blob url 放在隐藏的输入字段中,并且我也尝试了 blob.slice() 但到达服务器的只是对象 Blob。有谁知道如何获取 blob URL 的内容并将其发送到服务器?
任何帮助表示赞赏。