【问题标题】:Titanium appcelerator upload recorded video to serverTitanium appcelerator 将录制的视频上传到服务器
【发布时间】:2016-06-28 18:00:48
【问题描述】:

在我的 Appcelerator Titan 移动项目中,我必须录制视频并将其上传到我们的服务器。录制对我来说并不难,很简单,我可以正确返回视频网址:

Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'myVideo.mp4');

所以我可以得到本地路径:

myVideoPath =  f.nativePath;

从那里我不知道如何上传文件,对于图像我只是 base64 blob,但对于视频文件如何处理呢?

感谢您的宝贵帮助。

【问题讨论】:

    标签: appcelerator titanium-mobile appcelerator-titanium appcelerator-mobile


    【解决方案1】:

    普通的 XHR 请求:

    var f = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, "video.mp4");
    
    var xhr = Titanium.Network.createHTTPClient();
    xhr.onload = function(e) {
        // done
    };
    xhr.open('POST', 'http://server/upload.php');
    xhr.onsendstream = function(e) {
        console.log( Math.floor(e.progress * 100) + "%");
    };
    xhr.send({
        file: f
    });
    

    那么这取决于你的服务器架构。

    使用 php 会是这样的

    if(move_uploaded_file($_FILES['video_path']['tmp_name'], "test.mp4")) {
        return "success";
    } else{
        return "falied!";
    }
    

    【讨论】:

    • 在较旧的 Android(例如三星 Galaxy S4)上,对于大于 10 MB 的文件,此操作会失败并显示“java.lang.OutOfMemoryError”。
    猜你喜欢
    • 2023-03-28
    • 2021-07-07
    • 1970-01-01
    • 2015-11-25
    • 1970-01-01
    • 2013-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多