我正在尝试将视频上传到服务器,我可以从图库中选择视频,我正在通过webservice将该视频文件发送到服务器,但是没有调用该webservice请帮我如何上传视频以下是我的代码
var intent = Titanium.Android.createIntent({
action : Ti.Android.ACTION_PICK,
type : "video/*"
});
intent.addCategory(Ti.Android.CATEGORY_DEFAULT);
var chooser = Ti.Android.createIntentChooser(intent, "Select Video");
try {
var activity = $.win.getActivity().startActivityForResult(chooser, function(e) {
Ti.API.info("e:" + JSON.stringify(e));
if (e.resultCode === Ti.Android.RESULT_OK) {
Ti.API.info("e.video URL:" + e.intent.data);
var dataUri = e.intent.data;
var source = Ti.Filesystem.getFile(dataUri);
var mimeType = "video/mp4";
mimeType=encodeURIComponent(mimeType);
var fileData = Ti.Filesystem.getFile('appdata://videouptesting.mp4');
source.copy(fileData.nativePath);
Titanium.Media.saveToPhotoGallery(fileData);
if(fileData.exists())
{
var tmpName = (new Date()).getTime().toString()+'.mp4';
var fileContent = fileData.read();
var binaryString= Ti.Utils.base64encode(fileContent).toString();
binaryString = encodeURIComponent(binaryString);
var xhr = Titanium.Network.createHTTPClient();
var uploadUrl="http://183.82.113.143:2017/api/jsonws/Global-portlet.org_roles/add-file-entry";
var params="repositoryId="+ groupIdValue+"&folderId=0&sourceFileName="+ tmpName+"&mimeType="+ mimeType +"&title="+tmpName+"&description="+tmpName+"&changeLog="+tmpName+"&basecode64="+ binaryString;
xhr.onerror = function(e) {
Ti.UI.createAlertDialog({title:'Error', message:e.error}).show();
Ti.API.info('IN ERROR ' + e.error);
};
xhr.onload = function() {
Ti.API.info('In Image UPload Sucess message ');
Ti.API.info('IN ONLOAD ' + this.status + ' readyState ' + this.readyState);
var toast = Ti.UI.createNotification({
message :'Your image uploaded sucessfully',
duration : Ti.UI.NOTIFICATION_DURATION_LONG
});
toast.show();
};
xhr.onsendstream = function(e) {
ind.value = e.progress ;
Ti.API.info('ONSENDSTREAM - PROGRESS: ' + e.progress);
};
xhr.open("POST", uploadUrl);
xhr.setRequestHeader('Authorization', "Basic " + Ti.App.Properties.getString('userAuthEncodeData'));
xhr.setRequestHeader('Content-Type', 'multipart/form-data');
xhr.setRequestHeader('Content-Type', 'video/mp4');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send(params);
);
} catch(e) {
Ti.API.debug(e);
}