javascript - Ionic 3 Uygulamasında farklı türde dosyalarla birden fazla dosyayı sunucuya nasıl yükleyebilirim?


Ionic 3 kullanarak farklı uzantılara sahip (.jpg, .png, .doc, .pdf,) birden fazla dosya yüklemek istiyorum. Bir seferde sunucuya birden fazla dosya nasıl yükleyebilirim? Eğer herhangi bir çözüm varsa, lütfen burada paylaşın. Çok takdir edilecektir.

Kodum burada:

addImageORFileToEntry() {
 console.log("addImageORFileToEntry");

 if (this.plt.is('android')) {
  console.log("add files or image in android");

  this.fileChooser.open().then(uri => {
    // console.log("file uri", uri);
    this.filePath.resolveNativePath(uri).then((filePathResult)=>{
      console.log("file filePathResult", filePathResult);
      var fileName = filePathResult.substr(filePathResult.lastIndexOf('/') + 1);
      console.log("android file fileName", fileName);

      this.displayFile = fileName;
      console.log("this.displayFile" +JSON.stringify(this.displayFile));
      let onlyfilename = this.displayFile.split(".");
      // console.log("onlyfilename[0]" +onlyfilename[0]);
      let name = onlyfilename[0];
      var fileExtension = fileName.substr(fileName.lastIndexOf('.') + 1);
      console.log("android file fileExtension", fileExtension);
      this.extension = fileExtension;

      let filePathurl : string = filePathResult;
      // console.log("file uri filePathurl", filePathurl);

      this.base64.encodeFile(filePathurl).then((base64File: string) => {
        // console.log("file uri base64File", base64File);
        this.fileData = base64File;
        var newStringVal = this.fileData.replace(/ /g, "");
        // this.fileData = this.fileData.replace(/\s+/g, "");
        console.log("file uri this.fileData", this.fileData);

        let splitbase64 = this.fileData.split(',');
        // console.log("add files in android splitbase64", splitbase64[1]);
        this.getSplitbase64 = splitbase64[1];

        // console.log("add files in android this.getSplitbase64", this.getSplitbase64);
        // this.extensions.push({'extensions': this.extension})
        this.photos.push({'filename' : name, 'filestring': newStringVal, 'filetype': this.extension});
        console.log("file uri photos", this.photos);


      }, (err) => {
        console.log(err);
      });
    });
  }).catch(err => {
    console.log('Error', err);
  });
} else if (this.plt.is('ios')) {
  console.log("add files or image in ios");
  this.filePicker.pickFile().then(uri => {
    console.log("ios file uri" +JSON.stringify(uri));
    let correctPath = uri.substr(0, uri.lastIndexOf('/') + 1);
    console.log("ios file correctPath" +JSON.stringify(correctPath));
    let currentName = uri.substring(uri.lastIndexOf('/') + 1);
    console.log("ios file currentName" +JSON.stringify(currentName));
    let onlyfilename = currentName.split(".");
    console.log("onlyfilename[0]" +onlyfilename[0]);
    let name = onlyfilename[0];
    console.log("name" +name);
    let extension = onlyfilename[1];
    console.log("extension" +extension);
    this.file.readAsDataURL("file:///" + correctPath, currentName).then((base64File: string) =>{                           
      // console.log("ios file base64" +JSON.stringify(base64));
      this.fileData = base64File;
      var newStringVal = this.fileData.replace(/ /g, "");
      console.log("ios file fileData" +this.fileData);
      this.photos.push({'filename' : name, 'filestring': newStringVal, 'filetype': extension});
      console.log("file uri photos", this.photos);
    })
  });
}

}

ve rowData ile http post isteği kullanarak dosya yüklediğimde, hata alıyorum:

Bence büyük dosya geçerli bir base64 stringine dönüştürülmüyor. Bazı dosyalarda iyi çalışıyor, bazı dosyalarda çalışmıyor. Bu sorunu nasıl çözebilirim? Lütfen yardım edin.

İlgili makaleler