I am trying to record audio on iPhone using PhoneGap and then send this audio to the server. I use PhoneGaps Media APIs to record, and then PhoneGap file transfer APIs to send the file to the server.
I can make the recording just perfect, and its playback works great. However, when I try to send it to the server, the record appears on the server, but it says that the file is 0k in size.
I did a fairly extensive search on this issue and found others who had this problem. For example: https://groups.google.com/forum/#!topic/phonegap/zjzSs6JVokE
function win(r) { alert("Code = " + r.responseCode); alert("Response = " + r.response); alert("Sent = " + r.bytesSent); } function fail(error) { alert("An error has occurred: Code = " + error.code); console.log("upload error source " + error.source); console.log("upload error target " + error.target); } function upLoad() { var options = new FileUploadOptions(); options.fileKey="file"; options.fileName=myPath.substr(myPath.lastIndexOf('/')+1); options.mimeType="audio/wav"; var params = new Object(); var headers={'headerParam':'headerValue'}; options.headers = headers; options.chunkedMode = false; var ft = new FileTransfer(); ft.upload(encodeURI(myPath), encodeURI("http://myserver.com/upload.php"), win, fail, options); }
Here is the server side code:
print_r($_FILES); $new_image_name = "testFile.wav"; move_uploaded_file($_FILES["file"]["tmp_name"], "/var/www/wwwroot/recordings/".$new_image_name);
I think this may be a problem with the fact that I am sending .wav files. When I send a file, r.bytesSent usually shows between 200 and 400 bytes (regardless of the size of the file), so it seems that the actual contents of the file are simply not sent.
I tested the above code with a simple text file and it went fine, so I don't think these are permissions or syntax problems. I have not tried this with image files, but I canβt imagine that it greatly affects what I send.
Has anyone done this successfully?
source share