iOS: Upload encounters “Invalid URL server” with DATA_URL DestinationType in Ionic 4

I’ve been working on a project that uploads text data with captured image to a server. But then I’m encountering this error in iOS but it works well with Android. I already tried using NATIVE_URI and FILE_URI but no good.

Here is the error it produces in Xcode.

Here is my code:

const options: FileUploadOptions = {
                  fileKey: 'webcam',
                  fileName: 'dtr.jpg',
                  chunkedMode: false,
                  headers: {}
                };

const cameraOptions: CameraOptions = {
                  quality: 50,
                  destinationType: this.camera.DestinationType.DATA_URL,
                  encodingType: this.camera.EncodingType.JPEG,
                  mediaType: this.camera.MediaType.PICTURE,
                  allowEdit: false
                };

this.camera.getPicture(cameraOptions).then((imageData) => {
    this.yourImage = 'data:image/jpeg;base64,' + imageData;

    const endPoint = ENPOINT_URL;
    fileTransfer.upload(this.yourImage, endPoint, options)
        .then(
            (data) => {
                this.dismiss();
                $('.on-success').show();
            },
            (err) => {
                this.presentAlertConfirm(JSON.stringify(err));
            });
        }, (err) => {
            this.dismiss();
            this.presentAlertConfirm(JSON.stringify(err));
        });
...

Version information

  • MacOS Mojave 10.14.6
  • XCode 11
  • Ionic CLI 5.4.2
  • Cordova 9.0.0
  • Node 6.9.0