Cordova文件传输删除多部分或内容处理头 [英] Cordova File Transfer remove Multipart or Content-Disposition Header

查看:161
本文介绍了Cordova文件传输删除多部分或内容处理头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法使用Cordova文件传输插件将图片上传到我的服务器。

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);
};

但是,由于插件添加的额外标题,我的服务器读取图片时出现问题。 p>

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.

打开:\platforms\android\src\org\apache\cordova\filetransfer\FileTransfer.java

Open: \platforms\android\src\org\apache\cordova\filetransfer\FileTransfer.java

寻找:

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

注释或删除这两行。

同时删除:

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

此代码为multipart标头添加尾。

This code adds a tail for the multipart header.

我做了一个MD5校验和检查,他们现在是一样的。

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

这篇关于Cordova文件传输删除多部分或内容处理头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆