Upload array of photos to multer service


#1

Hello, i have big problem with a module of my app, i need to upload an array of files from my app like this way:

By the side of ionic i use this:

My provider method that get the local system url

resolveLocalUri(filePath:any){
    return this.file.resolveLocalFilesystemUrl(filePath)
}

By the sife of my page i convert each photo to file

for(var k = 0 ; k < this.photos.length; k++){
      var filePhoto = (<FileEntry>await this.nativeProvider.resolveLocalUri(this.photos[k]))
      filePhoto.file(file=>{
        this.files.push(file)
      })
    }

My uploader service

const formData = new FormData();
    let headers = new HttpHeaders();
    headers = headers.append('Authorization',token)
    //const reader = new FileReader();
    //reader.onloadend = ()=>{
      for(let i = 0; i < files.length; i++){
        formData.append(fileKey, files[i], files[i]['name'])
      }
    //}
    return this.http.post(this.url+params,formData,{headers:headers})

But nothing :frowning:

Some help please


#2

Does it need to be done in a form?
I am using ng2-file-upload with success with multer.

Here is an older post with working solution that I still use today with some modifications.
You could like skip a lot of the UI and just have one upload button.


#3

Thank you, i have the idea with this dependency but i don’t know where to put exactly my array of files, i look at the addToQueue function but it makes a multiple call to our back end, on my case i need only one request with an array of objects :frowning:

This is what i have until now on my service:

uploadData(files:any,fileKey:any,params:any,token:any):FileUploader{
    this.uploader = new FileUploader(
      {
        url:this.url+params,
        authTokenHeader:'Authorization',
        authToken: token
      }
    )
    this.uploader.onBuildItemForm = (item, form) => {
      form.append(fileKey, files);
      item.upload()
    };
    console.log(this.uploader)
    return this.uploader
  }

Thank you …


#4

Yes, that loops through the queue and uploads one at a time.
I do not personally upload as an array but here is some potential for you: