我想從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。 –