Phonegapfile upload:清空请求正文和文件

尝试使用FileTransfer插件将移动设备上的amrfile upload到带有Phonegap的服务器。

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 ); 

其中audio是媒体对象。

在服务器(nodejs)检查之后,请求对象的主体和文件属性是空的,并且头部中的内容长度被设置为0.看起来像文件没有正确地附加到请求。

这是因为你没有正确地设置你的path。 您需要使用绝对path才能完成此操作,您可以使用带有fullPath的requestFileSystem来获取此信息。

 window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){ fileSystem.root.fullPath; });