简体   繁体   English

科尔多瓦/ Phonegap FileTransfer iOS错误1

[英]Cordova / Phonegap FileTransfer iOS Error 1

I'm coding a Cordova app and it uploads image that have either been taken from the camera or from the gallery to a AWS server. 我正在编码一个Cordova应用程序,它会将从相机或图库拍摄的图像上传到AWS服务器。

I've set it up so it works perfect in android, but when I run the same code in iOS it doesn't run as intended. 我已经对其进行了设置,使其在android上完美运行,但是当我在iOS中运行相同的代码时,它并没有按预期运行。

The filetransfer upload returns an error 1, which according to the docs indicates the file to upload hasn't been found. 文件传输上传返回错误1,根据docs指示未找到要上传的文件。 However, the file URI I'm trying to transfer seems to be correct as I'm able to open that URI in Safari and it locates the image. 但是,我尝试传输的文件URI似乎是正确的,因为我能够在Safari中打开该URI并找到图像。

Here is the error: 这是错误:

FileTransferError {
code = 1;
source = "file:///Users/michael/Library/Application Support/iPhone Simulator/7.1-64/Applications/81CAB36F-9B14-42D3-8A00-06FE37A415EB/Documents/.thumbs/albumCover_b9f71c26291844c7f96a9a43fc4c61b6.jpg";
target = "http://***.s3.amazonaws.com/";}

And here is the code in question: 这是有问题的代码:

var url = "http://***.s3.amazonaws.com/";
            var uploadSuccess = function(r) {
                console.log("Full Image Uploaded");
            }
            var uploadError = function(error) {
                console.log("Upload Failed, Error: ", error.code);
            };
            var fullUpload = function() {
                socket.emit('getAWSCredentials', {pictureID: imageURI.substr(imageURI.lastIndexOf('/') + 1)}, function(policy) {
                    var options = new FileUploadOptions();
                    options.fileKey = "file";
                    options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
                    options.mimeType = "image/jpeg";

                    var params = {
                        AWSAccessKeyId: policy.awsKey,
                        policy: policy.policy,
                        signature: policy.signature,
                        key: policy.key,
                        acl: "public-read",
                        "Content-Type": "image/jpeg"
                    };
                    options.params = params;
                    options.chunkedMode = false;

                    var ft = new FileTransfer();
                    ft.upload(imageURI, encodeURI(url), uploadSuccess, uploadError, options);
                });
            }   
fullUpload();

I should note that I've clarified that the socket is returning the correct variables for the AWS authentication. 我应该注意,我已经澄清了套接字为AWS身份验证返回了正确的变量。

OK So fixed it myself. 好的,请自己修复。 Basically the code is mostly fine as above, but the input URI contained spaces which fileupload can't handle. 基本上,代码基本上和上面一样很好,但是输入URI包含fileupload无法处理的空格。

So I added the following code at the top: 因此,我在顶部添加了以下代码:

imageURI=imageURI.replace(/ /g,"%20");

Solved the problem. 解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM