$cordovaFileTransfer starts uploading to s3 and then fails


Hi Everyone,

I’m trying to have the user select some images from their gallery and then upload them to s3 using a presigned url that is returned from my server. I got all this working very well. The weird thing now is that the images randomly die during the upload process. Here is the log:

results[i], file:///…/tmp/cdv_photo_145.jpg
progress: 1.792584690709665
progress: 3.58516938141933
progress: 5.377754072128995
progress: 7.17033876283866
progress: 8.962923453548326
progress: 10.75550814425799
progress: 12.548092834967656
progress: 14.34067752567732
progress: 16.133262216386985
ERROR: {“code”:3,“source”:“file:///…/tmp/cdv_photo_145.jpg”,“target”:“https://bucket.s3-us-west-2.amazonaws.com/uploads/YaWaEYK5Djwxa4ZZZFq9mFmCFQecsvDj/cdv_photo_145.jpg?X-Amz-Algorithm=ASS4-HMAC-SHA256&X-Amz-Credential=AWSID/20150627/us-west-2/s3/aws4_request&X-Amz-Date=20150627T011212Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&X-Amz-Signature=d28e94698f1d59b1d4fa8344d38886c757199af92ed93839077c2a2b0f158daf",“http_status”:null,“body”:null,"exception”:null}

and here is the relevant code:

var ftOptions = new FileUploadOptions();
ftOptions.fileKey = ‘file’;
ftOptions.fileName = data_url.substr(data_url.lastIndexOf(’/’)+1);
ftOptions.mimeType = ‘image/jpeg’;
ftOptions.httpMethod = ‘POST’;
ftOptions.headers = {Connection : “close”};

$cordovaFileTransfer.upload(decodeURIComponent(data.url), data_url, ftOptions).then(function(result) {
console.log("SUCCESS: " + JSON.stringify(result.response));
}, function(err) {
console.log("ERROR: " + JSON.stringify(err));
}, function (progress) {
console.log("progress: " + (progress.loaded / progress.total) * 100);
}, false);

I’m currently using the ios-sim emulator. I would really appreciate any help! I’ve also tried using FileTransfer, but I couldn’t get it to actually upload the file (just the file name) – which is also how I know that my presigned S3 url is working properly.



Hi can you please share the complete code with us?