【问题标题】:How Can i Upload video to Vimeo From Node js Server我如何从 Node js 服务器上传视频到 Vimeo
【发布时间】:2020-11-26 06:35:12
【问题描述】:

这是我的代码来自客户端它正在工作我想从服务器执行此操作。

如何将视频上传到 Vimeo?

从客户端上传工作正常。 但我想从 Nodejs 服务器上传。

// 路线

const storage = multer.memoryStorage({
    destination: function (req, file, callback) {
        callback(null, '')
    }
})
const ShortFilm = multer({ storage }).single('file_loc')
 Server Uploadsrouter.post('/upload-short-film',ShortFilm, UploadShortFilm.UploadShortFilm)

// 代码

var filePath = req.file

let client = new Vimeo("key", "key", "key");

    var params = {
      'name': req.body.file_name,
      'description': req.body.file_desc
    }

    client.upload(filePath, params, function (uri) {
      
        // Get the metadata response from the upload and log out the Vimeo.com url
        client.request(uri + '?fields=link', function (error, body, statusCode, headers) {  
        
          if (error) {
            console.log('There was an error making the request.')
            console.log('Server reported: ' + error)
            return
          } 
          
          res.status(200).json({ "status": true, "Video-link": body.link });
          // console.log('"' + filePath + '" has been uploaded to ' + body.link)

          // Make an API call to edit the title and description of the video.
          client.request({
            method: 'PATCH',
            path: uri,
            params: {
              'name': req.body.file_name,
              'description': req.body.file_desc
            }
          },
           function (error, body, statusCode, headers) {
            if (error) {
              console.log('There was an error making the request.')
              console.log('Server reported: ' + error)
              return
            }

            console.log('The title and description for ' + uri + ' has been edited.')

            // Make an API call to see if the video is finished transcoding.
            client.request( uri + '?fields=transcode.status', function (error, body, statusCode, headers) {
                if (error) {
                  console.log('There was an error making the request.')
                  console.log('Server reported: ' + error)
                  return 
                }
                console.log('The transcode status for ' + uri + ' is: ' + body.transcode.status)
              }
            )
          })
        })
      },
      
      function (bytesUploaded, bytesTotal) {
        var percentage = (bytesUploaded / bytesTotal * 100).toFixed(2)
        console.log(bytesUploaded, bytesTotal, percentage + '%')

      },
      function (error) {
        console.log('Failed because : ' + error)
        res.status(200).json({ "status": false, "error": error });
      }
    )

Vimeo 表示应提供上传视频的文件路径。我怎样才能通过这个提供文件路径?

【问题讨论】:

    标签: node.js rest node-modules vimeo vimeo-api


    【解决方案1】:

    那是因为你没有给它文件名。 req.file 是一个包含很多字段的对象。尝试传递 req.file.path。

    假设你有这个定义。

    const multerPath = '/some/psth/to/multer';
    
    var storage = multer.diskStorage({
        destination: function(req, file, cb) {
            cb(null, multerPath);
        },
        filename: function(req, file, cb) {
            cb(null, file.originalname);
        }
    });
    

    那么你就可以拥有了。

    var filePath = req.file
    client.upload(`${multerPath}/${filePath.filename}`, params, function(uri) {
      ....
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-27
      • 1970-01-01
      • 2018-12-24
      • 2019-05-24
      • 2015-05-28
      相关资源
      最近更新 更多