Can i have 2 filekey attribute in a FileUploadOptions parameter IONIC3?

I want to upload 2 image file on the server, but unable to upload 2 image file in a same api. In JSON api there is 2 parameter which requires image file i.e id_proof_file_name and address_proof_name.

Rest Api function

register(imageidproof,imageaddproof, fullname, mobile_no, dob, address,
nominee_name,  id_proof_number,  add_proof_number): Promise<any> {
    return new Promise((resolve, reject) => {
      let oPtions = {
        fileKey: 'id_proof_file',
        params: {
          "full_name": fullname,
          "mobile_no": mobile_no,
          "dob": dob,
          "address": address,
          "nominee_name": nominee_name,
          "id_proof_number": id_proof_number,
          "add_proof_number": add_proof_number,
        chunkedMode: false

      let loading = this.loadCtrl.create({
        spinner: 'crescent',
        content: 'Please wait...',
        duration: 5000

      let bothimage = [];

      console.log("POST DATA " + JSON.stringify(oPtions));
      console.log("IMage Data", bothimage.toString());
      const fileTransfer: FileTransferObject = this.transfer.create();

      fileTransfer.upload(bothimage.toString(), URL + 'registration', oPtions, true).then(data => {
        let result = this.helper.parseData(data.response);
        console.log("Response from server", result);
        if (result.response == "true") {
        } else {
          this.helper.showALert(2, result.message);
      }).catch(err => {
        console.log("Something error happend", err);

and in upload function i tried to send the image in the array, but it through error string type is supported in this format.

I want to have 2 fileKey is it possible …?

1 Like

I would suggest forgetting about the FileTransfer plugin (especially since it’s been sunset) and simply using HttpClient to send the request. That will allow you to have as many images in a single request as you want.

While we’re at it, there’s no reason to have any (either implicitly or explicitly) anywhere in this code, and there’s no reason to be manually instantiating Promises.

1 Like

Thanks for your help, i have used another method which is base64 conversion.

1 Like