1
votes

I am trying to upload image from ionic application to S3 using presigned URL.

This is the current situation:

Ionic application sends request to server to get presigned upload URL from AWS S3.

On server side I have a node application that is using aws-sdk to get presigned URL and then returns it back to client.

This is my code on Ionic side that should upload file to AWS

var options = {
  fileKey: 'file',
  fileName: fileName,
  mimeType: 'image/jpeg',
  chunkedMode: false,
  timeout: 300000,
  httpMethod:'PUT',
  encodeURI: false,
  headers: {
    'Content-Type': 'image/jpeg'
  }
};
var ft = new FileTransfer();
ft.upload(cordova.file.dataDirectory + fileName, uploadLink, function () {
  console.log("image uploaded");
}, function (err) {
  console.log(err);
}, options);

This code works on iOS device, but when I deploy application to Android and try to upload file it fails with the following error:

FileTransferError body: null code:3 exception: "Write error: ssl=0x8ec63f80: I/O error during system call, Connection reset by peer" http_status: null source: "file:///data/user/0/com.ionicframework.xxxxxxxx/files/xxxxx.jpg" target: "https://xxxxxx.s3.eu-central- ..... "

Ionic info Cordova CLI: 6.4.0 Ionic CLI Version: 2.1.12 Ionic App Lib Version: 2.1.7

Android version on device is 6.0

I am a bit confused as it is work on iOS but it doesn't work on android. I have used cordova file transfer before and have never run into similar situation. However this is the first time that I am uploading files from android to S3 directly.

Any help would be highly appreciated.

1

1 Answers

1
votes

Ok, not sure what exactly is a problem, but the issue is definitely with the latest version of the cordova-plugin-file-transfer plugin (at this moment it is 1.6.0). This issue only reflects on android platform.

I have installed older version of the plugin (1.5.1) which "fixed" the issue. What I did to resolve my issue:

1) install latest version of cordova npm install -g cordova

2) install latest version of ionic npm install -g ionic

3) update android platform ionic platform update android

4) remove plugin ionic plugin remove cordova-plugin-file-transfer

5) install previous release of plugin ionic plugin add [email protected]

6) save changes to package.json ionic state save

7) ionic run android

I hope it will be useful for somebody.