0

so I use recorder.js to capture some audio and I use this code to upload the audio to our server:

 var url = URL.createObjectURL(blob);
 var au = document.createElement('audio');
 var li = document.createElement('li');
 var link = document.createElement('a');
 
 //name of .wav file to use during upload and download (without extendion)
 var filename = "test";

 //add controls to the <audio> element
 au.controls = true;
 au.src = url;

 //save to disk link
 link.href = url;
 link.download = filename+".wav"; //download forces the browser to donwload the file using the  filename
 link.innerHTML = "Save to disk";

 //add the new audio element to li
 li.appendChild(au);
 
 //add the filename to the li
 li.appendChild(document.createTextNode(filename+".wav "))

 //add the save to disk link to li
 li.appendChild(link);
 
 //upload link
    var xhr=new XMLHttpRequest();
    xhr.onload=function(e) {
        if(this.readyState === 4) {
            console.log("Server returned: ",e.target.responseText);
      Redirect();
        }
    };
    var fd=new FormData();
    fd.append("audio_data",blob, filename);
    xhr.open("POST","upload_audio.php",false);
    xhr.send(fd);

Here is the PHP:

  
<?php
print_r($_FILES); //this will print out the received name, temp name, type, size, etc.
$size = $_FILES['audio_data']['size']; //the size in bytes
$input = $_FILES['audio_data']['tmp_name']; //temporary name that PHP gave to the uploaded file
$output = $_FILES['audio_data']['name'].".wav"; //letting the client control the filename is a rather bad idea
//move the file from temp name to local folder using $output name
move_uploaded_file($input, "../data/".$output)
?>

This script works perfectly if you make recordings under 30 seconds. If the recordings become larger, we get this response from the server:

Server returned:    
Array
(
    [audio_data] => Array
        (
            [name] => QA_3_Issue,html,7fac7e13c55a4eb18b0f2160f8581097_7fac7e13c55a4eb18b0f2160f8581097
            [type] => 
            [tmp_name] => 
            [error] => 1
            [size] => 0
        )

)

Anyone has an idea what is going on? Might it be a server issue? I also dont really get why it says error but doesn't sho what exactly the error is.

Best regards, Daniel

HenryChinaski
  • 137
  • 1
  • 8

1 Answers1

1

You should set bigger file size for uploading in your .htaccess file or php.ini file, like upload_max_filesize = 100M. Hope, that helps.

Naomi
  • 46
  • 5