[英]Titanium Appcelerator image upload issue When call service without image
I have prepared an application with image upload. 我已经准备了带有图片上传功能的应用程序。 It sends some text and an image.
它发送一些文本和图像。
It's working fine when I add an image and content(text). 当我添加图像和内容(文本)时,它工作正常。 Unfortunately it's not working when I call the service without an image, see code below,
不幸的是,当我在没有图像的情况下调用该服务时,它无法正常工作,请参见下面的代码,
var params = {
file :$.selectedImageVw.image, //if file is not selected it will send as null
UserId : Ti.App.userID,
postContent : $.postMessage.value
};
var xhr = Titanium.Network.createHTTPClient();
xhr.onreadystatechange = function() {
if (this.readyState == 4) {
progressVw.hide();
// callback("Success");
// alert(this.responseData);
progressVw.hide();
xhr = null;
}
};
xhr.setRequestHeader('Content-Type', 'multipart/form-data');
xhr.setRequestHeader('enctype', 'multipart/form-data');
xhr.setRequestHeader('Content-length', params.length);
xhr.open("POST", "uploadUrl");
xhr.send(params);
I hope someone can help me. 我希望有一个人可以帮助我。 Thanks in advance!!
提前致谢!!
尝试使用http://requestb.in/之类的服务来检查客户端发出的请求是问题还是您使用的后端。
@FokkeZandbergan thanks for your respone, This issue resolve by very simple modification' @FokkeZandbergan感谢您的答复,此问题可通过非常简单的修改解决”
xhr.setRequestHeader('Content-Type', 'multipart/form-data'); xhr.setRequestHeader('Content-Type','multipart / form-data');
changed to 变成
xhr.setRequestHeader('Content-Type', "application/x-www-form-urlencoded"); xhr.setRequestHeader('Content-Type',“ application / x-www-form-urlencoded”);
Now its working with both imags and without images . 现在,它既可以 使用图像 ,也可以不使用图像 。
It may help to some one . 它可能对某些人有所帮助。 :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.