这是我用于将图像上传到服务器的 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 中的问题还是我需要在代码中更改的任何内容。
请帮我。