2013-03-28 2 views
2

나는 https://github.com/cwilso/AudioRecorder을 사용하고 있으며 모든 것이 잘 돌아가는 것을 제외하고는 blob을 가져 와서 서버로 보냅니다. 양식 데이터를 서버로 보내는 다음과 같은 작업을 수행합니다. 기본적으로 wav 파일은 클라이언트 측에서 생성 된 다음 blob에 저장되며 해당 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의 내용을 가져 와서 서버로 보내는 방법을 아는 사람이 있습니까?

도움을 주시면 감사하겠습니다.

답변

2

당신은 나는 바보해야합니다 formData.append('thename', theblob);

+0

처럼, FormData에 방울을 추가 할 수 있습니다. 나는 하루 종일 여기에 있었다. 나는 당신이 이전에 제안한 것을 시도했지만 그것이 효과가 없다고 생각했다. 그래서 귀하의 의견을보고, 나는 wireshark를 실행 트래픽을 캡처하고 파일이 실제로 서버로가는 것을 보았다. PHP는 $ _FILES에서 그것을받습니다. 그리고 나는 잘못된 var 이름도 가지고 있습니다. 감사합니다 – Nic

+0

@ 닉 당신은 환영합니다 – Musa

+0

감사합니다, 시간을 많이 절약 .. –

관련 문제