我想从Titanium Appcelerator中的android模拟器,Genymotion和移动设备上传视频文件。不能上传大于500kb的视频文件大小到Android服务器中的Android服务器
我上传从模拟器捕获200到300kb左右的小文件工作正常,我很成功。它的上传和从服务器获得响应。
当我试图上传周围3-5MB文件,然后我没有收到来自服务器的响应。 有些时候,我在2-4分钟后得到的回应太迟,当时文件被上传。但经常没有上传,也没有得到回应。
我尝试了不同的代码发布在网上,但没有得到运气100%。
在日志上的数据流,我可以看到进程0-1但对于大文件,其在.9999x停止,它不是在1
[INFO] : ONSENDSTREAM - PROGRESS: 0.9998882582315288
[INFO] : ONSENDSTREAM - PROGRESS: 0.9999253846335128
[INFO] : ONSENDSTREAM - PROGRESS: 0.9999625110354967
[INFO] : ONSENDSTREAM - PROGRESS: 0.9999996374374807
到达这里是测试我的示例代码。
钛按钮单击
var intent = Titanium.Android.createIntent({
action : Ti.Android.ACTION_PICK,
type : "video/*"
});
intent.addCategory(Ti.Android.CATEGORY_DEFAULT);
$.index.activity.startActivityForResult(intent, function(ei) {
if (ei.error) {
alert("Error");
} else {
var dataUri = ei.intent.data;
var xhr = Titanium.Network.createHTTPClient(/*{enableKeepAlive:false}*/);
xhr.setTimeout(1000 * 60 * 5);
xhr.open('POST', 'http://gaurangchhatbar.in/ws/apitest/videouploadcode.php');
xhr.setRequestHeader("enctype", "multipart/form-data");
xhr.setRequestHeader('Cache-Control', 'no-cache');
xhr.onerror = function(ex) {
alert(ex.error);
};
xhr.onload = function() {
alert(this.responseText);
};
xhr.onsendstream = function(ex) {
Ti.API.info('ONSENDSTREAM - PROGRESS: ' + ex.progress);
};
var filename = "UploadedFile-" + (new Date()).toString();
filename = filename.replace(/\./g,"-");
filename = filename.replace(/\:/g,"-") + ".mp4";
Ti.API.info(filename);
var source = Ti.Filesystem.getFile(dataUri);
var fileData = Ti.Filesystem.getFile(Ti.Filesystem.getApplicationDataDirectory(), filename);
source.copy(fileData.nativePath);
if (fileData.exists()) {
var fileContent = fileData.read();
if (fileContent)
xhr.send({
video_path : fileContent,
action : "uploadvideo"
});
else
alert('Did not get any data back from file content');
} else
alert('Did not get a file data for : ' + dataUri);
}
});
PHP代码
$target_path = "video/";
$target_path = $target_path . basename($_FILES['video_path']['name']);
if(move_uploaded_file($_FILES['video_path']['tmp_name'], $target_path)) {
return "success";
} else{
return "falied!";
}
我试图原生的Android应用程序从链接上传文件:Android Native App for Upload File to Server
这是伟大的工作。
任何人都知道为什么响应需要太多时间吗?或者让我知道我是否忘记了任何东西。
我对
Appcelerator Studio, build: 4.5.0.201602170821 Titanium SDK 5.2.2.GA Alloy Project Mac OS X EI Capitan Version 10.11.4
这是一个错误,我已经发布了解决您的问题!仍然需要做一些测试,然后才能创建PR。但是您可以添加两行,并使用此解决方案构建自己的工作SDK https://jira.appcelerator.org/browse/TIMOB-20483?focusedCommentId=385890&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel #comment-385890如果您需要修复,请立即致电 – miga
感谢Nils和miga,我在SDK 5.3.0.v20160513184909中下载并测试了它,但也未能解决问题。你能否提供一些帮助如何使用提供的解决方案构建工作SDK。 –