Plugin File Transfer is not working at ios


#1

i’m trying to upload my server a file on the device. android upload is good. but ios has trouble.

The response is 200 in the log, and the server does not log the request.

On Android, the request is normal and the upload related log is normal on the server side, but it does not work well on iOS.

This is my code

private instRprtFile(): void {
        this.prmt.fileWrteTc = 'C';
        let loading = this.loadingCtrl.create({ content: 'Please wait...' });
        loading.present();
        this.http.post({ url: 'CB102.slctNextFileSno.do', data: this.prmt, isLoading: false }).then((data1: any) => {
            this.prmt.fileSno = data1.fileSno;
            let isStop = false;
            for (let i=0,n=this.items.length; i<n; i++) {
                console.log(this.items[i]);
                console.log(this.prmt);
                let options: FileUploadOptions = {
                    chunkedMode: false,
                    fileKey: 'files',
                    fileName: this.items[i].title,
                    headers: { 'X-Requested-With': 'XMLHttpRequest' },
                    params: this.prmt
                }

                this.fileTransfer.upload(encodeURI(this.items[i].uri), encodeURI('http://localhost:8080/CB102.instRprtFile.do'), options).then((data) => {
                    if(i == n-1) {
                        loading.dismiss();
                        this.sendReport();
                    }
                }).catch((error) => {
                    console.log(error);
                    loading.dismiss();
                    isStop = true;
                    this.dltnRprt();
                    this.openErrorMessage(error);
                });
                this.prmt.fileSno = this.prmt.fileSno + 1;
                if(isStop) break;
            }
        });
    }

In the app, CB102.instRptFile.do is called to upload, but the server does not actually response it, so no log is output.

On Android, the log for the CB102.instRptFile.do call comes up normally on the server

config.xml


<plugin name="cordova-plugin-file-opener2" spec="^2.0.19" />
<plugin name="cordova-plugin-filepath" spec="^1.1.0" />
<plugin name="cordova-plugin-filechooser" spec="^1.0.1" />
<plugin name="cordova-plugin-file" spec="^5.0.0" />
<plugin name="cordova-plugin-file-transfer" spec="^1.7.0" />
<engine name="ios" spec="4.5.4" />
<engine name="android" spec="6.3.0" />

ionic info

please help me…

I translated a Google translator about the immature English language.

thank you


#3

Hi. I have a very similar problem, in Android the upload works very well, but in iOS it doesn’t work, when I send the request nothing happens, neither a 200 or any other response.

This is my code

public doSelectPhotoImage (sourceType:number, uploadURL:string) {
      
      const options: CameraOptions = {
        quality         : 80,
        destinationType : this.camera.DestinationType.FILE_URI,
        sourceType      : sourceType, // this.camera.PictureSourceType.CAMERA
        encodingType    : this.camera.EncodingType.JPEG,
        mediaType       : this.camera.MediaType.PICTURE
      }
      
      this.camera.getPicture(options).then((imagePath) => {
        
        // Special handling for Android library
        if (this.isPlatformAndroid()) { 
          if (sourceType !== this.camera.PictureSourceType.CAMERA) {
            this.filePath.resolveNativePath(imagePath)
              .then(filePath => {
                this.sendFileAndData(filePath, uploadURL, {});
            });
          } else {
            this.sendFileAndData(imagePath, uploadURL, {});
          }
          
        } if (this.isPlatformIOS()) {
          this.sendFileAndData(normalizeURL(imagePath), uploadURL, {});
          
        } else {
          this.sendFileAndData(imagePath, uploadURL, {});
        }
        
      }, (err) => {
        console.log(err);
      });
      
  }



  public sendFileAndData (fileURL:string, uploadURL:string, params) {

    console.log("fileURL=" + fileURL);
    
    let options: FileUploadOptions = {
      fileKey: "fileParamName",
      chunkedMode: false,
      params: params
    };
    
    this.cordovaFileTransfer.upload(fileURL, uploadURL, options).then(
      (result) => {
        console.log("Result: " + result);
      }, (err) => {
        console.log("ERROR: " + err);
      }
    ).catch((err) => {
      console.log("ERR: " + err);
    });
    
  }
  

Nothing is printed in the console.

I also have read and follow the instructions in this article without success:

I have uninstalled and re-installed the plugin and the dependencies of file-transfer, also re-installed all the project dependencies, but the result is the same.

I have tested in the emulator and in a real device, iPhone 6 with iOS 11.

ionic-info:
ionic-info

I have spent 2 weeks without success, any help will be very appreciated.
Thanks in advance!


#4

I had a similar problem, it worked on android but not on ios

Try to create the FileTransferObject inside of platform.ready, that solved it

  fileTransfer: FileTransferObject;
  constructor(public transfer: FileTransfer, public platform: Platform) {
     this.platform.ready().then(
      (ready)=>{
        this.fileTransfer= this.transfer.create();
      }
    );
  }

#5

I’m facing a similar issue with the “camera” plugin…

Everything works fine on android but the error “Plugin not installed” raises on iOS.

Have you found a solution for you problem … ?

Thx

Salva.


#6

I faced the same problem under iOS while under Android everything was working.

@Zakkusu’s solution solved the issue :slight_smile:


#7

Thanks a lot for your answer !!!