问题描述
我什至不知道从哪里开始这个。我正在使用 Vimeo API 将视频上传到 vimeo。成功生成了一个访问令牌,我有权上传。但是,当我指定要上传的视频时,即使我的路径正确,也会收到错误消息:“失败,因为:无法找到要上传的文件”:O
这里是负责上传的代码部分:
var uploadv = document.getElementById("uploadvideo");
uploadv.addEventListener("click",function() {
var Vimeo = require('./indextwo').Vimeo
console.log('clicked');
try {
var config = require('./example/config.json')
} catch (error) {
console.error('ERROR: For this example to run properly you must create an API app at ' +
'https://developer.vimeo.com/apps/new and set your callback url to ' +
'`http://localhost:8080/oauth_callback`.')
console.error('ERROR: Once you have your app,make a copy of `config.json.example` named ' +
'`config.json` and add your client ID,client secret and access token.')
process.exit()
}
if (!config.access_token) {
throw new Error('You can not upload a video without configuring an access token.')
}
// Instantiate the library with your client id,secret and access token (pulled from dev site)
var client = new Vimeo(config.client_id,config.client_secret,config.access_token)
// Create a variable with a hard coded path to your file system
var filePath = '../testvideo.mp4'
console.log('Uploading: ' + filePath)
var params = {
'name': 'Vimeo API SDK test upload','description': "This video was uploaded through the Vimeo API's NodeJS SDK."
}
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
}
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': 'Vimeo API SDK test edit','description': "This video was edited through the Vimeo API's NodeJS SDK."
}
},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',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)
}
)
})
我认为问题出在代码的最后一部分:
function (bytesUploaded,function (error) {
console.log('Failed because: ' + error)
}
)
如果我可以提供更多部分代码以便您有更好的想法,请告诉我!提前致谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)