钛HTTPCLIENT可以't上载文件
Titanium HTTPCLIENT can't upload file
我尝试使用浏览器可以上传文件,但如果我使用Titanium上传,它就不起作用,brower代码是浏览器上传文件:
<form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
Upload.php文件:
$tmp_file=$_FILES['file']['tmp_name'];
$target_file=basename($_FILES['file']['name']);
move_uploaded_file($tmp_file, "files/".$target_file);
我的钛代码是:
var webaddress = 'http://' + address.value + ':' + port1.value + '/scanbatch/index.php';
xhr.open('POST',webaddress);
xhr.send({files : Titanium.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'scanbatch.txt')});
它可以工作,但web服务没有收到任何东西,只是收到了一个标头。
顺便说一句,我可以通过httpclient发送简短的xml,但如果xml更长,有时它无法发送,则失败的时间更长,我的意思是不总是,如果xml超过512KB,它总是失败。
我的代码是
var webaddress = 'http://' + address.value + ':' + port1.value + '/liveho/scanbatch';
xhr.open('POST',webaddress);
xhr.send(xmlscript);
我的加载功能是
onload : function(e) {
alert(this.responseText);
},
请帮我谢谢
我会给你一些建议,以缩小问题范围(钛方面)。
你测试过文件的路径是否正确吗?
var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory +
Ti.Filesystem.getSeparator() + 'scanbatch.txt');
if(file.size)
xhr.send({files : file});
else
Ti.API.info("File " + file.nativePath + " doesn't exist or is empty");
如果路径不正确,请尝试在resourcesDirectory:中查找
var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory +
Ti.Filesystem.getSeparator() + 'scanbatch.txt');
断开连接的问题可能是减少设置超时属性。oneror函数也可以帮助您找到问题。onsendstream属性会让您知道上传的进度。
Ti.Network.createHTTPClient({
...
onload : function(e) {
alert(this.responseText);
},
onerror : function(e) {
Ti.API.debug(e.error);
alert(e.error);
},
onsendstream : function(e) {
var progress = parseFloat(e.progress)*100;
Ti.API.info("Upload progress:" + progress + "%");
//e.progress will contain a value from 0.0-1.0 with the progress of the upload
alert("Upload progress:" + progress + "%");
},
timeout : 5000 // in milliseconds
...
});
相关文章:
- 通过CSV文件上载更新数据库表
- 带有凭据的角度文件上载(CORS)不起作用
- 使用AJAX将文件上载到服务器
- 需要帮助处理XML HTTP文件上载请求
- 使用Javascript中的Dropbox Core API将文件上载到Dropbox
- JQuery文件上载未检测到动态添加的输入
- 通过将文件上载到ASHX处理程序来实现SSE(服务器发送的事件)
- 将 FormData 对象放入数组中以从不同的输入文件上载文件
- 恢复连接后上载文件
- 在react native中通过PUT方法上载文件
- 钛HTTPCLIENT可以't上载文件
- AJAX POST函数未上载文件
- 使用Angular上载文件时,HttpPostedFileBase为null
- 文件输入更改时正在上载文件
- PhoneGap Ajax上载文件
- 如何使用$.ajax()上载文件
- 上载文件,但不能在表单中上载
- 正在使用getElementByClassName上载文件
- 通过本地文件路径上载文件
- 无法使用bootstrapValidator Ajax上载文件