Uploading a file from S3 to youtube, using this code:
s3.setBucket('MyBucket');
s3.get('MyBucket/5/' + filename, null, 'stream', function(err, response) {
googleapis.discover('youtube', 'v3').execute(function(err, client) {
var metadata = {
snippet: { title: title, description: description},
status: { privacyStatus: 'public' }
};
client
.youtube.videos.insert({ part: 'snippet,status'}, metadata)
.withMedia('video/mp4', response)
.withAuthClient(auth)
.execute(function(err, result) {
if (err) console.log(err);
else console.log(JSON.stringify(result, null, ' '));
response.redirect('/share?set=yt&id=' + result.id);
}); }); });
does not work, because the line:
.withMedia('video/mp4', response)
It's a replacement of the original one, that works:
fs.readFileSync('/temp/myfile.png')
In other words: If I upload a local file on my laptop, this will work because I'm using the filesystem object.
In case anyone is looking for the answer, here it is:
var googleapis = require('googleapis'),
OAuth2 = googleapis.auth.OAuth2,
ytdapi = googleapis.youtube('v3'),
AWS = require('aws-sdk'),
s3 = new AWS.S3;
var s3data = {
Bucket: 'BUCKET_NAME',
Key: 'VIDEO_NAME'
};
s3.getObject(s3data, function (err, data) {
var params = {
auth: oauth2Client,
part: 'snippet,status',
resource: {
snippet: {
title: 'Title',
description: 'Description'
},
status: {
privacyStatus: 'public'
}
},
media: {
mimeType: 'video/mp4',
body: data.Body
}
};
ytdapi.videos.insert(params, function (err, result) {
if (err) console.log(err);
else console.log(JSON.stringify(result, null, ' '));
});
});
This question is a bit old but here is how I uploaded a video stored in S3 to Youtube using NodeJS v6.10.3.
const AWS = require('aws-sdk'); // v1.6.0
const s3 = new AWS.S3({region: 'eu-west-1', apiVersion: '2006-03-01'});
const {google} = require('googleapis'); // v26.0.1
const YoutubeApi = google.youtube('v3');
const s3data = {
Bucket: bucketName,
Key: fileName
};
let fileStream = s3.getObject(s3data).createReadStream();
const params = {
auth: oauth2Client, // create this using 'google-auth-library'
part: 'snippet,status',
resource: {
snippet: {
title: 'Title',
description: 'description'
},
status: {
privacyStatus: 'private'
}
},
media: {
mimeType: 'video/mp4',
body: fileStream // stream to stream copy
}
};
YoutubeApi.videos.insert(params, function (err, result) {
if (err) {
console.error('error');
console.error(err);
}
else {
console.log('success');
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With