I am getting "Code 3" (connection error) error when trying to upload an image file from my Cordova / Phonegap 3.2 app to Amazon S3 using FileTransfer and in Android 4.3 version platform.
options.fileKey = "file";
options.fileName = filename_for_s3;
options.mimeType = "image/jpeg";
options.chunkedMode = false;
options.headers = {
Connection: "close"
}
ft.upload(imageURI, encodeURI("https://" + data.Bucket + ".s3.amazonaws.com/"), success, fail, options);
The code works on iOS7 and older Android versions (tested on Android 3.2 and 2.3), but my problem is with version 4.3. I assume that the problem is not with the code itself, as it works with other version, but might be the Phonegap library itself.
There might be a workaround but I am not familiar with it. I tried many options posted on what it seems like a similar problem, like changing the chunkedMode to false, without encoding the URI, adding "Connection: 'close'" header but it still doesn't work. Others suggested that this might be an issue with the google analytics plugin that causes it, so I removed it and I still get the same error. I also tried the answers in this question without success.
I also want to add that I am generating a signature and policy on the server.
options.params = {
"key": "uploads/" + filename_for_s3,
"AWSAccessKeyId": data.AWSAccessKey,
'success_action_status': '201',
"acl": "private",
"policy": data.Policy,
"signature": data.Signature
};
Cors permissions are also set as needed:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<ExposeHeader>ETag</ExposeHeader>
<ExposeHeader>x-amz-meta-custom-header</ExposeHeader>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
Update: I also checked the Amazon S3 logs, but there isn't any line related to an upload.
I've spent a few days trying to figure it out without any success. I hope that you can help me solve this issue. Thanks.
It seems like this is a bug in Cordova 3.2 (see my post here). I was suggested to use the latest FileTransfer library, and also updated the File library, however I get an error when compiling.
I need help to solve this issue.
Update: updating the FileTransfer, File and Capture plugins to the newest version didn't solve the problem, in fact, now it throws Code 3 on iOS7 too - didn't happen before.