【发布时间】:2015-12-16 01:39:29
【问题描述】:
我正在使用 Phonegap 5.3.1 和 Android 22。我正在尝试使用 phonegap 的 Filetransfer api 将图像传输到远程服务器。
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageData.substr(imageData.lastIndexOf('/')+1);
alert("The filename here is : " + imageData);
所以这里会打印 imageData
content //com.android.providers.media.documents/document/image/image%3A53
还有下面的代码
imageData.substr(imageData.lastIndexOf('/')+1);
是否分配 options.fileName = "image%3A53"
这不是我在设备上的图像名称。在我看来,这导致了一个问题。
用于运行 FileTransfer 插件的 javascript 表示文件已成功传输,但我在服务器上找不到该文件(运行 PHP)。
服务器响应如下:
得到服务器的响应
Array
(
[file] => Array
(
[name] => image%3A53
[type] => image/jpeg
[tmp_name] => /tmp/php8qjZXN
[error] => 0
[size] => 137490
)
)
也有少数帖子说: Phonegap android unable to upload image using fileTransfer
您不能使用 FileTransfer 上传方法中从相机成功回调中获得的 imageUri,您必须首先将 uri 解析为这样的文件名:
navigator.camera.getPicture(function(imageURI){
window.resolveLocalFileSystemURI(imageUri, function(fileEntry) {
fileEntry.file(function(fileObj) {
var fileName = fileObj.fullPath;
//now use the fileName in your method
//ft.upload(fileName ,serverURL + '/ajax.php?fname=appuploadspotimage'...);
});
});
});
任何帮助将不胜感激。
【问题讨论】:
-
137490 字节是正确的文件大小吗?如果是这样,我会说您的服务器正在获取文件。你在
/tmp/php8qjZXN发现了什么? -
文件大小似乎正确。我还得到以下 -bash: cd: /tmp/php8qjZXN: No such file or directory
-
我们能看到处理请求并存储文件的 PHP 吗?
-
-
看起来是不是 PHP 脚本出错了?
标签: javascript android phonegap-plugins