How can javascript upload a blob?

前端 未结 6 2144
旧时难觅i
旧时难觅i 2020-11-22 11:29

I have a blob data in this structure:

Blob {type: \"audio/wav\", size: 655404, slice: function}
size: 655404
type: \"audio/wav\"
__proto__: Blob
6条回答
  •  北海茫月
    2020-11-22 11:48

    I was able to get @yeeking example to work by not using FormData but using javascript object to transfer the blob. Works with a sound blob created using recorder.js. Tested in Chrome version 32.0.1700.107

    function uploadAudio( blob ) {
      var reader = new FileReader();
      reader.onload = function(event){
        var fd = {};
        fd["fname"] = "test.wav";
        fd["data"] = event.target.result;
        $.ajax({
          type: 'POST',
          url: 'upload.php',
          data: fd,
          dataType: 'text'
        }).done(function(data) {
            console.log(data);
        });
      };
      reader.readAsDataURL(blob);
    }
    

    Contents of upload.php

    
    

提交回复
热议问题