在没有777的情况下上传视频无效

时间:2015-06-01 11:29:25

标签: javascript angularjs node.js video file-upload

我在本地测试我的节点视频上传。我的上传课程如下:

    var videoExtensions = ['mp4', 'webm', 'mov'];
var audioExtensions = [];
//Media object
function Media(file, targetDirectory) {
    this.file = file;
    this.targetDir = targetDirectory;
}

Media.prototype.isVideo = function () {
    return this.file.mimetype.indexOf('video') >= 0;
};
Media.prototype.isAudio = function () {
    return this.file.mimetype.indexOf('audio') >= 0;
};
Media.prototype.getName = function () {
    return this.file.originalname.substr(0, this.file.originalname.indexOf('.'))
};

router.route('/moduleUpload')
    .post(function (request, response) {
        var media = new Media(request.files.file, '../user_resources/module/' + request.body.module_id + '/');
        if (!fs.existsSync(media.targetDir)) {
            fs.mkdirSync(media.targetDir, 0777, function (err) {
                if (err) {
                    console.log(err);
                    response.send("ERROR! Can't make the directory! \n");    // echo the result back
                }
            });
        }
        if (media.isVideo()) {
            convertVideos(media);
        }
        else if (media.isAudio()) {
            convertAudio(media);
        }
        else {
            moveFile(media);
        }
        response.status(200).json('user_resources/module/' + request.body.module_id + '/' + media.getName());
    });


router.route('/retrieveFile')
    .post(function (request, response) {
        var path = '../' + request.body.data;
        var file = fs.createReadStream(path);
        file.pipe(response);
    });


function convertVideos(media) {
    var ffmpeg = require('fluent-ffmpeg');
    videoExtensions.forEach(function (extension) {
        var proc = new ffmpeg({source: media.file.path, nolog: false})
            .withVideoCodec('libx264')
            .withVideoBitrate(800)
            .withAudioCodec('libvo_aacenc')
            .withAudioBitrate('128k')
            .withAudioChannels(2)
            .toFormat(extension)
            .saveToFile(media.targetDir + media.getName() + '.' + extension,
            function (retcode, error) {
                console.log('file has been converted succesfully');
            });
    });
}

function convertAudio(media) {
    var ffmpeg = require('fluent-ffmpeg');
    audioExtensions.forEach(function (extension) {
        var proc = new ffmpeg({source: media.file.path, nolog: false})
            .withVideoCodec('libx264')
            .withVideoBitrate(800)
            .withAudioCodec('libvo_aacenc')
            .withAudioBitrate('128k')
            .withAudioChannels(2)
            .toFormat(extension)
            .saveToFile(media.targetDir + media.getName() + '.' + extension,
            function (retcode, error) {
                console.log('file has been converted succesfully');
            });
    });
}

上传视频文件时,会将其转换为3个不同的文件。

现在,我希望上传的文件位于我的/Video文件夹中,这个文件没有任何权限。导致上传无法播放。但是,只要我将文件的权限更改为777,视频就会毫无问题地播放。

我的问题是为什么?我在上传中遗漏了哪些内容并且chmod 777明智吗?

还要注意使用ubuntu 14.04

0 个答案:

没有答案