我可以轻松地将视频更新为Youtube:
var googleapis = require('googleapis');
googleapis.discover('youtube', 'v3').execute(function(err, client) {
var metadata = {
snippet: { title:'title', description: 'description'},
status: { privacyStatus: 'private' }
};
client
.youtube.videos.insert({ part: 'snippet,status'}, metadata)
.withMedia('video/mp4', fs.readFileSync('user.flv'))
.withAuthClient(auth)
.execute(function(err, result) {
if (err) console.log(err);
else console.log(JSON.stringify(result, null, ' '));
});
});
问题是对于fs.readFileSync
非常不实用的大型文件。
显然是this was fixed,但提供的示例适用于Google云端硬盘:
var fs = require('fs');
var drive = google.drive({ version: 'v2', auth: oauth2Client });
drive.files.insert({
resource: {
title: 'testimage.png',
mimeType: 'image/png'
},
media: {
mimeType: 'image/png',
body: fs.createReadStream('awesome.png') // read streams are awesome!
}
}, callback);
如何使用信息流上传到Youtube?
答案 0 :(得分:2)
在我的情况下,我可以使用此模块上传大文件(> 2GB)。
var youtube = require('googleapis').youtube('v3');
youtube.videos.insert({
'auth': auth,
'resource': resource,
'part': part,
'media': fs.createReadStream(videoFilePath)
}, callback);