NgCordova FileTransfer direct download to AWS S3 WebKitFormBoundary Issue

I am trying to upload a file using a pre-signed URL on AWS-S3 with the ngCordova FileTransfer plugin.

I successfully upload files to AWS-S3, but the contents of the file contain

------WebKitFormBoundarylCFgJXqqECF1rJ2m Content-Disposition: form-data; name="file"; filename="75cae09191bd92a16c3ff05baeb88b9b.jpg" Content-Type: image/jpeg

Because of what the image file cannot be opened. How can I get rid of this header in my file. I have an idea that if I put binary data instead of form data, this will get rid of it, since I tested it in POSTMAN, but could not find a way to do this in the cordova file transfer.

  $cordovaFileTransfer.upload(s3SignedUrl, imagePathOnPhone, { fileKey: "file", fileName: localFileName, httpMethod: "PUT", mimeType: 'image/jpeg' }) .then(function (result) { console.log(result); }, function (error) { console.log(error); }, function (progress) { console.log(progress); }); 

My bucket is in Frankfurt and api v4. and I use nodejs on the server.

+6
source share
2 answers

Try adding the Content-Type property to the params section.

 $cordovaFileTransfer.upload(s3SignedUrl, imagePathOnPhone, { fileKey: "file", fileName: localFileName, httpMethod: "PUT", mimeType: 'image/jpeg', params: { "Content-Type": "image/jpeg" } }) .then(function (result) { console.log(result); }, function (error) { console.log(error); }, function (progress) { console.log(progress); }); 
+1
source

Try adding "Content-Type": "image/jpeg" to opts.headers to disable multipart:

 $cordovaFileTransfer.upload(s3SignedUrl, imagePathOnPhone, { fileKey: "file", fileName: localFileName, httpMethod: "PUT", mimeType: 'image/jpeg', headers: { "Content-Type": "image/jpeg" } }) .then(function (result) { console.log(result); }, function (error) { console.log(error); }, function (progress) { console.log(progress); }); 
0
source

All Articles