samples/youtube/upload.js
async function runSample(fileName) {
  const fileSize = fs.statSync(fileName).size;
  const res = await youtube.videos.insert(
    {
      part: 'id,snippet,status',
      notifySubscribers: false,
      requestBody: {
        snippet: {
          title: 'Node.js YouTube Upload Test',
          description: 'Testing YouTube upload via Google APIs Node.js Client',
        },
        status: {
          privacyStatus: 'private',
        },
      },
      media: {
        body: fs.createReadStream(fileName),
      },
    },
    {
      // Use the `onUploadProgress` event from Axios to track the
      // number of bytes uploaded to this point.
      onUploadProgress: evt => {
        const progress = (evt.bytesRead / fileSize) * 100;
        readline.clearLine(process.stdout, 0);
        readline.cursorTo(process.stdout, 0, null);
        process.stdout.write(`${Math.round(progress)}% complete`);
      },
    }
  );
  console.log('\n\n');
  console.log(res.data);
  return res.data;
}
async function runSample(fileName) {
  const fileSize = fs.statSync(fileName).size;
  const res = await youtube.videos.insert(
    {
      part: 'id,snippet,status',
      notifySubscribers: false,
      requestBody: {
        snippet: {
          title: 'Node.js YouTube Upload Test',
          description: 'Testing YouTube upload via Google APIs Node.js Client',
        },
        status: {
          privacyStatus: 'private',
        },
      },
      media: {
        body: fs.createReadStream(fileName),
      },
    },
    {
      // Use the `onUploadProgress` event from Axios to track the
      // number of bytes uploaded to this point.
      onUploadProgress: evt => {
        const progress = (evt.bytesRead / fileSize) * 100;
        readline.clearLine(process.stdout, 0);
        readline.cursorTo(process.stdout, 0, null);
        process.stdout.write(`${Math.round(progress)}% complete`);
      },
    }
  );
  console.log('\n\n');
  console.log(res.data);
  return res.data;
}
async function runSample ( fileName ) { const fileSize = fs . statSync ( fileName ) . size ; const res = await youtube . videos . insert ( { part : 'id,snippet,status' , notifySubscribers : false , requestBody : { snippet : { title : 'Node.js YouTube Upload Test' , description : 'Testing YouTube upload via Google APIs Node.js Client' , } , status : { privacyStatus : 'private' , } , } , media : { body : fs . createReadStream ( fileName ) , } , } , { // Use the `onUploadProgress` event from Axios to track the // number of bytes uploaded to this point. onUploadProgress : evt => { const progress = ( evt . bytesRead / fileSize ) * 100 ; readline . clearLine ( process . stdout , 0 ) ; readline . cursorTo ( process . stdout , 0 , null ) ; process . stdout . write ( ` ${ Math . round ( progress ) } ` ) ; } , } ) ; console . log ( '\n\n' ) ; console . log ( res . data ) ; return res . data ; }
very basic example of uploading a video to youtube
very basic example of uploading a video to youtube