javascript Cordova/Phonegap FileTransfer.upload() 错误代码 = 1 (FILE_NOT_FOUND_ERR)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22815101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cordova/Phonegap FileTransfer.upload() error code = 1 (FILE_NOT_FOUND_ERR)
提问by rory
What's really confusing is when I capture the image with the phone camera, I use FileTransfer.moveTo
and it sends the image to a specified folder on my SD card as desired. I also keep a list of image objects in localStorage
that looks something like this:
真正令人困惑的是,当我使用手机摄像头拍摄图像时,我使用FileTransfer.moveTo
并将图像根据需要发送到我 SD 卡上的指定文件夹中。我还保留了一个图像对象列表localStorage
,看起来像这样:
[
Object
ean: "42208556"
image: "file:///storage/sdcard0/PhotoscanPhotos/d51b5b77-aab1-9947-096d-b0a92dfb87eafoto.jpg"
timestamp: 1396441761000
__proto__: Object
etc etc
As part of my app, i use the same image[i].image as src attribute to dynamically add images to a list and it works fine. However, using the same parameter for FileTransfer.upload
gives me the above error.
作为我的应用程序的一部分,我使用相同的 image[i].image 作为 src 属性来动态地将图像添加到列表中,并且它工作正常。但是,使用相同的参数 forFileTransfer.upload
给了我上述错误。
My function is a near replica of the API docs(Cordova 3.1). Code is as follows:
我的函数几乎是API 文档(Cordova 3.1)的复制品。代码如下:
function uploadImagesAsJpegs(imageObject) {
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName=imageObject.image.substr(imageObject.image.lastIndexOf('/')+1);
//alert(options.fileName);//debugging ............we're happy with this
options.mimeType="image/jpeg";
options.chunkedMode = true;
var serverUrl = http://172.17.7.112/mylocalserver;
var params = {};
params.value1 = ean;
params.value2 = imageObject.timestamp;
options.params = params;
var fileTransfer = new FileTransfer();
//alert(encodeURI(serverURL));//debugging ............we're happy with this
//alert("image to upload is: " + imageObject.image);//debugging............we're happy with this
fileTransfer.upload(imageObject.image, encodeURI(serverURL), onUploadSuccess, onUploadFail, options);
}
采纳答案by rory
Serverside script was wrong... naturally I should have figured that out given the obvious FileTransferError.FILE_NOT_FOUND_ERR
error message. Apologies for wasting everyone's time and thank you for making the effort.
服务器端脚本是错误的......鉴于明显的FileTransferError.FILE_NOT_FOUND_ERR
错误消息,我自然应该想到这一点。很抱歉浪费了大家的时间,并感谢您的努力。
回答by Anheledir
I believe setting options.chunkedMode = false;
is solving most issues during file upload, maybe give it a try.
我相信设置options.chunkedMode = false;
可以解决文件上传过程中的大多数问题,不妨试试看。
回答by Nasenbaer
What I would try is: 1. use exclusivemode for upload (true at the end)
我会尝试的是: 1. 使用独占模式上传(最后为真)
fileTransfer.upload(imageObject.image, encodeURI(serverURL), onUploadSuccess, onUploadFail, Options, true);
fileTransfer.upload(imageObject.image, encodeURI(serverURL), onUploadSuccess, onUploadFail, Options, true);
Try to move data first to the local store of device instead of working with SD Card storage. Perhaps it is a Case of permission and you just are able to upload from phone local storage.
Make sure the Image is not pending in another Image as imagesource and you have full Access to the data. Perhaps read&write is needed exclusive.
尝试首先将数据移动到设备的本地存储,而不是使用 SD 卡存储。也许这是一个许可案例,您只能从手机本地存储上传。
确保该图像未作为图像源在另一个图像中挂起,并且您具有对数据的完全访问权限。也许读写是需要独占的。