How to do PUT request with FileTransfer


#1

I’m developing an application in Ionic 2 and I’m trying to send to the backend the dataUser object that contains fields like first_name and last_name and more the image of the user selected from the device gallery thanks to ImagePicker.
To use FileTransfer to make the PUT of the user image and the various user data I do

...
const fileTransfer: TransferObject = this.transfer.create();
imageLocation = this.avatar[0];

let options: FileUploadOptions = {
        fileKey: 'avatar',
        httpMethod: 'PUT',
        headers: { 'Authorization': 'JWT ' + this.token },
        params: this.dataUser
}
      
fileTransfer.upload(imageLocation, encodeURI('http://ENDPOINT'), options, true)
            .then((data) => {
                console.log('put request success -> ' + data);                 
             }, error => {
                console.log(error);
             });

The problem is that when I run the upload method, the PUT is successful because I print to the console the message “put request success ->”, but the data value is undefined.
From the backend log I see that a PUT request has arrived but actually does not upload any data.
some ideas?


#2

I wonder if using an https endpoint would have any effect.


#3

Are you saying to replace http with https?


#4

I’m saying it’s worth a try. iOS in particular seems to be concerned with sending data to non-secure endpoints.