Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

multipartform data - Cordova File Transfer remove Multipart or Content-Disposition Header

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....
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Took me awhile to figure this but this is the way I removed the Multipart Header. Here's the solution/work around.

Open: platformsandroidsrcorgapachecordovafiletransferFileTransfer.java

Look for:

sendStream.write(beforeDataBytes);
totalBytes += beforeDataBytes.length;

Comment away or delete these 2 lines. They are the code that adds the multipart header.

Also remove:

sendStream.write(tailParamsBytes);
totalBytes += tailParamsBytes.length;

This code adds a tail for the multipart header.

I have done a MD5 checksum check and they are of the same now.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...