【发布时间】: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