Downloading PhoneGap.wav from an iOS device creates a 0k file on the server

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?

+4
source share
1 answer

I managed to solve this a few days ago. This is about the myPath variable in the sample question. myPath cannot be anything but the tmp folder (a temporary folder / device is created) Therefore, when you try to send a file, you know for sure that a copy of this file was made in the tmp folder. So do this immediately before ft.upload:

 myPath = myPath.replace(myFolderPath, 'tmp'); 

In my case, myFolderPath was "Documents \ media". The document path is the place where files created by the user are stored on your device.

I hope this saves people from all google search pages visited :)
(This worked for phonegap 3.0.0)

+1
source

Source: https://habr.com/ru/post/1490181/


All Articles