gpt4 book ai didi

javascript - Phonegap 文件上传 : Empty request body & files

转载 作者:搜寻专家 更新时间:2023-11-01 00:45:27 24 4
gpt4 key购买 nike

尝试使用 FileTransfer 将 amr 文件从移动设备上传到带有 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
);

其中音频是 Media对象。

在服务器 (nodejs) 检查时,请求对象的正文和文件属性为空, header 中的内容长度设置为 0。似乎文件没有正确附加到请求。

最佳答案

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

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

关于javascript - Phonegap 文件上传 : Empty request body & files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19944655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com