Upload pictures and other data to server


#1

Hi all,

I’m triing to load a picture with oteher data. I’m using the fileTransfert plugin https://github.com/apache/cordova-plugin-file-transfer.

```indent preformatted text by 4 spaces`
var fileURL =myPicturesURL;
var options = new FileUploadOptions();
options.fileKey = “pictures[]”;
options.fileName = fileURL.substr(fileURL.lastIndexOf(’/’) + 1);
options.mimeType = “image/jpeg”;
options.httpMethod = “POST”;
options.headers = {
“Authorization”: auth,
“Content-Disposition”: ‘form-data;name=“myData”,name=“pictures[]”’,
“Content-Type”: undefined
};
var params = {};
params.myData = JSON.stringify({myName:“test”;myAge:“30”});
options.params = params;
var ft = new FileTransfer();
var deferred = $q.defer();
ft.upload(fileURL, publishPostPath, function (data) {
if (data.response) {
deferred.resolve(data);
} else {
deferred.reject(data);
}
}, function (error) {
deferred.reject(error);
}, options);


The result should be:

Content-Type: multipart/form-data; charset=utf-8;

–boundary
Content-Disposition: form-data; name=“myData”

–boundary
Content-Disposition: form-data; name=“pictures[]”;filename="pictures001.jpeg"
Content-type:image/jpeg


The problem is that only myData json is send to server, and the pictur isn't send. Maybe my problem is the Content-Type?


thanks