Transfer Plugin: Image transfer not working

The file transfer of images to our server via post is not working correctly. Our nginx fails with error 411 stating that we need to set a length (411 Length Required). I tried to set the content-length in the request headers, but that did not work.

i use the camera like this (in a separated function from the upload itself):

let options = {
        correctOrientation: true,
        destinationType: Camera.DestinationType.FILE_URI
    };

Camera.getPicture(options).then(
      (imageData) => {
            console.log(imageData);
            this.lastTakenPicture = imageData;
      });

and want do do the file upload as following:

let filePath = this.lastTakenPicture;
let file = this.lastTakenPicture.substr(this.lastTakenPicture.lastIndexOf('/') + 1);
let path = this.lastTakenPicture.substr(0, filePath.indexOf(file));
let uri = encodeURI(Globals.DICMS_API_URI + 'profile/photo-upload-gallery');
let _headers = this.apiClient.createCustomHttpHeaders('post', 'multipart/form-data');
let ft = new Transfer();


window.resolveLocalFileSystemURL(filePath, function (fileEntry) {
   fileEntry.getMetadata(function(metadata) {
        let fileSize = metadata.size;
        let options = {
                 fileKey: "file",
                 fileName: file,
                 headers: _headers,
                 method: 'post',
                 params: {
                            param1: 'param1value'
                 },
                 chunkedMode: false
         };
         options.headers.append('CONTENT-LENGTH', fileSize);
         console.log(options);

          ft.upload(filePath, uri, options, true).then(
                        success => console.log(success),
                        error => console.log(error)
                    );
  });

But the problem is, that this does not work. I tried the whole day to get it to work, but no luck.

Edit: fixed typo

1 Like

having the same issue

So it turns out, that this is only working when using HTTP, but when switching to HTTPS it fails with error 411.

edit:
i still have no idea why the plugin behaves like this. is there any possibility to see the raw http request the plugin is emitting?

edit2:
i also changed my code and removed the header content-length param, the creation of custom headers (i’m gonna creating my own array of key/value pairs for authentication headers) and i’m just using the default values of the plugin.

let _headers = {
                'X-TOKEN1': TOKEN1VAL,
                'X-TOKEN1': TOKEN2VAL,
                'X-PARAM': PARAMVAL,
                'X-ACCEPT-VERSION': '1'
            };

            let options = {
                headers: _headers,
                fileName: file,
                params: {
                    param1: 'param1value'
                }
            };

            ft.upload(filePath, uri, options).then(
                success => console.log(success),
                error => console.log(error)
            );

Hi @all

after investigation this issue, it turns out, that our load balancers were running on an old nginx version. after updating them the plugin works as expected.

:+1: