Tianium 5.1.1.GA SDK映像文件未在ios中上载
这是我的HTTPClient代码,用于将图像上载到服务器。同样适用于3.5.0.GA SDK和4.1.0.GA SDK,但不适用于新SDK 5.1.1.GA和5.1.2.GATianium 5.1.1.GA SDK映像文件未在ios中上载,ios,appcelerator,titanium-mobile,appcelerator-titanium,Ios,Appcelerator,Titanium Mobile,Appcelerator Titanium,这是我的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, f
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内部服务器错误
是SDK中的问题还是我需要在代码中更改的任何内容
请帮助我。下面的代码演示了文件上载。根据您的代码进行修改
f1 = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,<image name>);
i1 = f1.read();
xhr = Titanium.Network.createHTTPClient();
xhr.open('POST','<url to call>', false); // false makes it synchronous
xhr.onload = function() { handleAfterSentRouting(this.responseText); };
xhr.send({media1: i1}); // media1 is the field the file information is in when you upload
f1=tianium.Filesystem.getFile(tianium.Filesystem.applicationDataDirectory,);
i1=f1.read();
xhr=Titanium.Network.createHTTPClient();
xhr.open('POST','',false);//false使其同步
xhr.onload=function(){handleeftersentrouting(this.responseText);};
xhr.send({media1:i1});//media1是上载时文件信息所在的字段
谢谢。几周后,我遇到了同样的问题和解决方案,非常简单,您只需在服务器上创建另一个web服务页面,用于文件上载,而不传递任何其他文本参数,在您的情况下,编辑您的xhr.send参数以仅包含您的文件,如下所示:
xhr.send({
file : uploadingFile
});
因此,为其他变量创建另一个与另一个web服务器页面相关的xhr函数:
claimId : claimID,
filename : filename,
description : ''
它有效;) 500错误表示您的服务器正忙或此时没有响应。请检查您的url是否正常工作。您的服务器上载脚本中也可能有错误。相同的url和相同的代码在3.5.0.GA SDK和4.1.0.GA SDK中工作。所以我的假设是服务器上传脚本不错。刚刚在4.1.0GA中试用,效果不错。我在5.1.1GA中再次尝试,但它不起作用。我遇到了相同的问题。仍在调查解决方案。