Eray
Eray

Reputation: 312

Is it possible send array for image? (Ionic File Upload)

I have an array like this.

["file:///data/user/0/io.ionic.starter/files/1542283317507.jpg",null,
 "file:///data/user/0/io.ionic.starter/files/1542283320931.jpg"]

I'm trying to send this array(name's final) via fileTransfer upload function. But it returns error. Btw it's workin' for single image which out of array. How can i send that's array.

  fileTransfer.upload(final, url, options).then(
  data => {
    console.log(data);

    this.presentToast("Image succesful uploaded.");
  },
  err => {
    this.presentToast("Error while uploading file.");
  }
);

}

Thanks for helping!

Upvotes: 0

Views: 312

Answers (1)

iStornZ
iStornZ

Reputation: 848

You can try this, not tested but it should work.

var promises = [];
var filesArray = ["file:///data/user/0/io.ionic.starter/files/1542283317507.jpg",
 "file:///data/user/0/io.ionic.starter/files/1542283320931.jpg"];

filesArray.forEach((element) => {
  var uploadPromise = fileTransfer.upload(<YOUR_FINAL>, element, <YOUR_OPTIONS>);
  promises.push(uploadPromise);
});


Promise.all(promises)
.then((result) => {
  console.log('All files uploaded !');
}

Upvotes: 1

Related Questions