Uploading multiable images at once


#1

Hi
I need to upload multiable images in the same request to the api , the api should receive 4 images in the post request , however I was able to know how to send one image but I couldn’t find how to send more than one image at a time , here is my code for the one image :

var url = "site.com/upload";
      var filepath = this.nidP;
      console.log(filepath);
      var options = {
        fileKey: "residency_image",
        fileName : "image",
        httpMethod: "POST",
        mimeType: "image/jpeg",
        params: {id: data.id},
        chunkedMode: true
      }
      const fileTransfer: TransferObject = this.transfer.create();
      fileTransfer.upload(filepath,url , options, true).then(function(){
        console.log('uploaded');
      });

as I said this code is able to upload inly one image whereas I need to upload four images at once. I searched in the documentations for a way but didn’t find what I want and I searched in google but no luck.
Thanks guys


#2

Did you write the backend? Are you certain it is capable of accepting 4 files at once in a single request? That would surprise me. Why can’t you make four parallel transfer objects on the same URL?


#3

sadly I’m not the one who wrote the back-end code , the request should have the four files with (different keys of course)
as you can see in the picture :


#4

I think it’s wanting four separate upload requests, not four files in a single request.


#5

when I tried to upload one picture I got this error :

{"frontside_image":["The frontside image field is required."],"leftside_image":["The leftside image field is required."],"backside_image":["The backside image field is required."],"rightside_image":["The rightside image field is required."]}

and from what I know about the developer who wrote the back-end code I’m sure it’s in the same request


#6

I don’t think it’s natively supported (see this discussion). You can try adapting the strategy proposed here.


#7

What format does it say those four images are? How big are they? You could send multiple base 64 strings of the images…but there’s no way to know if that’s what they want.


#8

well to make things easier I contacted the back-end developer and he changed the API to receive each image in an individual request

Thank you guys