0

i am trying to download images from s3 server using cordova-plugin-file-transfer

my code works with other images from google or diffrent servers. but when i tried to download from s3 it shows error.

downloadimg ="https://s3.amazonaws.com/bucket/img/5.jpg";           
var fileTransfer = new FileTransfer();
var uri = encodeURI(downloadimg);
var package_root = cordova.file.externalRootDirectory + ".appname";
var imgindex = downloadimg.lastIndexOf("/") + 1;
var imgname = downloadimg.substr(imgindex);
var fileURL = package_root + imgname;
console.log(uri);
console.log(fileURL);
fileTransfer.download(
uri,
fileURL,
function (entry) {
console.log("success");
},
function (error) {
    console.dir(error);
},
false,
{
    headers: {
        "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
    }
}
);

i tried adding {encodeURI:false}; and 'Content-type':'image/jpg' in option header but did not work.

1 Answers1

0

Try this:

  1. Enable CORS configuration.
  2. Remove header auth
  3. Check buckets policy (you can test making the object public)

Hope to help you.

ene_salinas
  • 705
  • 4
  • 11
  • please post your CORS configuration – ene_salinas Oct 31 '18 at 15:28
  • * GET 3000 Authorization – mayur sawant Oct 31 '18 at 15:32
  • i have set content-Type : image in metadata and for content-Disposition only "attachement" option available if i set content-Disposition to attachement the image url directly get downloads in chrome , does not display image. – mayur sawant Oct 31 '18 at 15:42
  • ok, I thought that you need download image, remove attachment ;) – ene_salinas Oct 31 '18 at 22:40
  • err i get from filetransfer plugin body:"InvalidArgumentUnsupported Authorization TypeAuthorizationBasic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA==C4E0DF318D79BA76mzZOiZnZEVZ19AtKEVc21ULjmd0Tl6L+uAA/uOEASEkC3zlx5qW9FNkzCYaHXciLaPKU78H7Nbc=" code:1 exception:"https://s3.amazonaws.com/bucket/img/5.jpg" http_status:400 source:"https://s3.amazonaws.com/bucket/img/5.jpg" target:"file:///storage/emulated/0/app/5.jpg" – mayur sawant Nov 01 '18 at 06:42
  • Please, Make public this image and try again – ene_salinas Nov 02 '18 at 05:05
  • Also remove header auth – ene_salinas Nov 02 '18 at 05:06