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