D
D
Deefs2017-07-08 20:36:14
PHP
Deefs, 2017-07-08 20:36:14

How to send the recorded file to the server in another way?

At the moment, sending is in base64 format, it takes a very long time to wait 4 seconds for the loader to appear, are there any ways to facilitate sending?

audioRecorder.send=function(el){
  var post_id = $(el).attr('post-id');
      	var user_id = $(el).attr('user-id');
      	var page_id = $(el).attr('page-id');
  var audioRecorderElem=$(el).parents('.audioRecorder');
  var reader=new FileReader();
  reader.onloadend=function(){
    var base64=reader.result;
    

    //здесь посылаешь base64 на сервер

    $.post("file.php", {"audio" : base64}, function(data){
            console.log(data);
            console.log('stop');
          var text = '[audio records/' + data +'.wav]';  
          ///alert(text);
          var esc = $.Event("keyup", { keyCode: 13 });
          esc.keyCode = 13;
          esc.shiftKey = 0;
         
          Wo_RegisterCommentClick(text, post_id, user_id,  page_id);
          });
    
  };
  reader.readAsDataURL(audioRecorder.blob);
};


FILE.PHP

<?php
if(isset($_POST['audio'])){
  $audio = $_POST['audio'];
  $audio = str_replace('data:audio/wav;base64,', '', $audio);
  $decoded = base64_decode($audio);
  $namefile = time();
  $file_location = "/home/asd/public_html/records/".$namefile.".wav";
 
  file_put_contents($file_location, $decoded);
  echo $namefile;
}
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2017-07-08
@BorisKorobkov

loading very long

Can't you see the connection?
Are your photos in BMP and video in DV? :-)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question