簡體   English   中英

Javascript Blob 保存到變量

[英]Javascript Blob save to variable

我正在使用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 的內容並將其發送到服務器?

任何幫助表示贊賞。

您可以向FormData添加一個 blob,例如formData.append('thename', theblob);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM