Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70612

Upload pictures and other data to server

$
0
0

@bubbobne wrote:

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

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70612

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>