NodeJS Cloudinary上传视频

时间:2017-01-10 19:17:16

标签: node.js video upload cloudinary

这是cloudinary文档页面。 http://cloudinary.com/documentation/upload_videos#uploading_from_server_side_code

根据文档,视频上传如下代码。

var videoFile = req.files.video.path;    
cloudinary.uploader.upload(videoFile,
                function(result) {console.log(result); },
                { resource_type: "video" });

此外,它支持没有像这样的图像文件上传。

var videoFile = req.files.video.path;
cloudinary.uploader.upload(videoFile,
                function(result) {console.log(result); },
                { resource_type: "raw" });

也是我的html文件:

<form action="/videos/add" enctype="multipart/form-data" method="post">
                    <div class="form_line">
                        <label for="video_title">Title:</label>
                        <div class="form_controls">
                            <input id="video_title" name="title" size="30" type="text" />
                        </div>
                    </div>
                    <div class="form_line">
                        <label for="video">Video:</label>
                        <div class="form_controls">
                            <input id="video" name="video" type="file" />
                        </div>
                    </div>
                    <div class="form_line">
                        <div class="form_controls">
                            <button type="submit" class="btn btn-danger">Submit Video</button>
                        </div>
                    </div>
                    <input id="direct" name="direct" type="hidden" />
                </form>

即使我指定了资源类型,我也会收到这两个代码的错误。

{"error":{"message":"Invalid image file"}}

https://github.com/cloudinary/cloudinary_npm/issues/26

Upload video to Cloudinary

我该如何解决这个问题?

...谢谢

1 个答案:

答案 0 :(得分:0)

您还可以以块的形式上传视频,这非常适合大文件。

cloudinary.uploader.upload_large(file, 
            function(result) {console.log(result); }, 
            { resource_type: "video" });

    v1_result_adapter = function(callback) {
 if (callback != null) {
 return function(result) { if (result.error != null) { 
callback(result.error); return;} else { callback(void 0, result); return; } }; } else { return null; } };