Sending Audio Blob to server

大兔子大兔子 提交于 2019-12-06 06:34:19

You send a data URL instead of a Blob; FileReader is not necessary if expected result is to POST Blob or File object. You can send the File object itself, as File inherits from Blob

$('#save_oralessay_question_btn').click(function(e) {

  var question_content = $('#question_text_area').val();
  var test_id_fr = parseInt($('#test_id_fr').val());
  var question_type = parseInt($('#question_type').val());
  var rubric_id_fr = $('#rubric_id_fr').val();

  var result = $.post('../questions', {
      question_content: question_content,
      question_type: question_type,
      test_id_fr: test_id_fr,
      rubric_id_fr: rubric_id_fr,    
      audio_data: audio_files[0],
      processData: false,
      contentType: false
    }, function(data) {
      var html = "<div class='row  col-md-4'><div class='col-md-offset-6'><i class='fa fa-check fa-5x' aria-hidden='true'></i></div></div>";

      swal({
        title: "Success!",
        text: data,
        type: "success",
        timer: 2000
      }, function() {
        //location.reload();
      });

    })
    .done(function(data) {

    }).fail(function(xhr, status, error) {
      sweetAlert("Error!", error, "error");
    });

});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!