I want to upload audio file on my server using nativescript-background-http plugin. The mobile side is working fine. no runtime error. The log shows complete upload but when I visit the directory on my server, no file is uploaded.
Here's my code on nativescript
var session = bghttp.session("image-upload");
var audioFolder = fs.knownFolders.documents().getFolder("audio");
var recordedFile = audioFolder.getFile("recording.mp3");
var request = {
url: "http://talktext.me/talktext.me(app)/recAudio.php",
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
"File-Name": "recording.mp3"
},
description: "{ 'uploading': '" + "recording.mp3" + "' }"
};
alert(recordedFile.path);
let params = [
{ name: "test", value: recordedFile.path },
{ name: "fileToUpload", filename: recordedFile.path, mimeType: 'audio/mpeg' }
];
var task = session.multipartUpload(params, request);
task.on("progress", logEvent);
task.on("error", logEvent);
task.on("complete", logEvent);
function logEvent(e) {
console.log("UPLOAD STATUS: "+e.eventName);
}
Here's my code on recAudio.php
$all_headers = apache_request_headers();
$newimg = file_put_contents('uploads/' . $all_headers['File-Name'],
file_get_contents('php://input'));
Everything on mobile is working fine. But no file is uploaded on the server.