Node.js 如何从Node js服务器向Vimeo上传视频
这是我在客户端的代码,它正在工作。我想从服务器上完成这项工作 如何将视频上传到Vimeo 从客户端上传工作正常。 但是我想从Nodejs服务器上传它 //路线Node.js 如何从Node js服务器向Vimeo上传视频,node.js,rest,node-modules,vimeo,vimeo-api,Node.js,Rest,Node Modules,Vimeo,Vimeo Api,这是我在客户端的代码,它正在工作。我想从服务器上完成这项工作 如何将视频上传到Vimeo 从客户端上传工作正常。 但是我想从Nodejs服务器上传它 //路线 const storage = multer.memoryStorage({ destination: function (req, file, callback) { callback(null, '') } }) const ShortFilm = multer({ storage }).single(
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说应该提供上传视频的文件路径。如何通过此文件提供文件路径?这是因为您没有为其提供文件名。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) {
....
});