I managed to upload an image to my server using Cordova File Transfer plugin.
var img = <full path to image>
var url = <url to webservice>
var options = new FileUploadOptions(); //no specified options, using defaults
var ft = new FileTransfer();
ft.upload(img, encodeURI(url), win, fail, options);
var win = function (r) {
console.log('Successfully sent');
}
var fail = function (error) {
console.log("An error has occurred: Code = " + error.code);
};
However, my server had problems reading the image due to the extra header added by the plugin.
--+++++..Content-Disposition: form-data; name="file"; filename="filename.jpg"..Content-Type: image/jpeg....
Took me awhile to figure this but this is the way I removed the Multipart Header. Here's the solution/work around.
Open: \platforms\android\src\org\apache\cordova\filetransfer\FileTransfer.java
Look for:
Comment away or delete these 2 lines. They are the code that adds the multipart header.
Also remove:
This code adds a tail for the multipart header.
I have done a MD5 checksum check and they are of the same now.
Please add headers to options
Just refer the example from GitHub.
Just put a 'Content-Type' in Headers.
https://github.com/apache/cordova-plugin-file-transfer#example-with-upload-headers-and-progress-events-android-and-ios-only
Based on the source code:
You can find it is easy to disable the multipart header by setting a dummy header option in your javascript: