Ionic file and file chooser


#1

I want to upload/select a file from the mobile So I’m using ionic file & filechooser plugins. This is my code.

fileData: any;
uploadFile() {
    this.fileChooser.open().then((uri) => {
       console.log(uri);

       this.file.resolveLocalFilesystemUrl(uri).then((newURL) => {
         console.log(JSON.stringify(newURL));

         let dirPath = newURL.nativeURL;
         let dirPathSegments = dirPath.split('/');   // break string into array
         dirPathSegments.pop() // removes the file name
         dirPath = dirPathSegments.join('/')
 
         this.file.readAsArrayBuffer(dirPath, newURL.name).then(async (buffer) => {
          await this.upload(buffer,newURL.name)
         })
       })
    }) 
  }

  async upload(buffer, name) {
    this.fileData = new this.fileData([buffer],{ type:"pdf" });
  }

I want to store the buffer & name in variable. I have stored it the variable fileData. Is it is correct approach for storing a file in a variable called fileData.If it is wrong can someone help me in the coding?