Reputation: 30009
Trying to upload an amr file from a mobile device to a server with Phonegap, using the FileTransfer plugin.
var uri = "./" + $scope.audio.src;
$scope.audio.release();
var options = new FileUploadOptions();
options.fileKey = "audio";
options.fileName = uri.substr(uri.lastIndexOf('/') + 1);
options.mimeType = "audio/AMR";
options.httpMethod = "POST";
options.chunkedMode = false;
console.log("Options:", options);
options.params = {
exhibitId: $scope.id,
title: $scope.title,
email: $scope.email
};
var ft = new FileTransfer();
ft.upload(uri, encodeURI("http://someurl.com/api/recording/create"),
$scope.uploadSuccess,
$scope.uploadFailure,
options
);
Where audio is a Media object.
Upon inspection at the server (nodejs), the request object's body and file properties are empty and the content-length in the headers is set to 0. Seems like the file is not being properly attached to the request.
Upvotes: 2
Views: 754
Reputation: 570
It's because you aren't setting your path properly. You need to use an absolute path in order to do this, you can use requestFileSystem with fullPath to get this information.
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function(fileSystem){
fileSystem.root.fullPath;
});
Upvotes: 3