【发布时间】:2016-01-20 06:36:39
【问题描述】:
这是我用于将图像上传到服务器的 HTTPClient 代码。这同样适用于 3.5.0.GA SDK 和 4.1.0.GA SDK,但不适用于新的 SDK 5.1.1.GA 和 5.1.2.GA。
var filename = "sample.png";
//Pointer to the file to be uploaded.
var uploadingFile = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, filename);
Ti.API.info('uploadingFile ' + uploadingFile.exists());
//We are creating a new xhr instead of calling the existing one because we dont want timeout when uploading data.
var xhr = Titanium.Network.createHTTPClient({
validatesSecureCertificate : false,
enableKeepAlive : true,
onload : function() {
uploadingFile = null;
Ti.API.info('Success '+tthis.responseText);
},
onerror : function(data) {
uploadingFile = null;
Ti.API.info('this.status '+this.status);
}
});
xhr.onsendstream = function(e) {
var uploadTime = new Date();
Ti.API.info('UPLOADING PROGRESS: ' + progress + ' ' + uploadTime.getHours() + ":" + uploadTime.getMinutes() + ":" + uploadTime.getSeconds());
};
xhr.open('POST', httpClient.getUserDomainInfo(config.URLs.imageupload, tenant));
xhr.send({
file : uploadingFile.read(),
claimId : claimID,
filename : filename,
description : ''
});
错误状态为 500 Internal Server Error。
是 SDK 中的问题还是我需要在代码中更改的任何内容。
请帮帮我。
【问题讨论】:
-
500 错误表示您的服务器当时正忙或没有响应。请检查您的网址是否正常。
-
您的服务器上传脚本也可能有错误
-
相同的 URL 和相同的代码适用于 3.5.0.GA SDK 和 4.1.0.GA SDK。所以我的假设是服务器上传脚本很好。刚刚在 4.1.0GA 中尝试过它工作。我再次尝试在 5.1.1GA 中它不起作用。
-
我遇到了同样的问题。仍在研究解决方案。
标签: ios appcelerator titanium-mobile appcelerator-titanium