examples/s3-backup-file.js
function uploadNewBackup(s3, backupTmpFilePath, bucket, key) {
  return new Promise((resolve, reject) => {
    debug(`Uploading from ${backupTmpFilePath} to ${bucket}/${key}`);

    function uploadFromStream(s3, bucket, key) {
      const pass = new stream.PassThrough();

      const params = {
        Bucket: bucket,
        Key: key,
        Body: pass
      };
      s3.upload(params, function(err, data) {
        debug('S3 upload done');
        if (err) {
          debug(err);
          reject(new VError(err, 'Upload failed'));
          return;
        }
        debug('Upload succeeded');
        debug(data);
        resolve();
      }).httpUploadProgress = (progress) => {
        debug(`S3 upload progress: ${progress}`);
      };

      return pass;
    }

    const inputStream = fs.createReadStream(backupTmpFilePath);
    const s3Stream = uploadFromStream(s3, bucket, key);
    inputStream.pipe(s3Stream);
  });
}
function uploadNewBackup(s3, backupTmpFilePath, bucket, key) {
  return new Promise((resolve, reject) => {
    debug(`Uploading from ${backupTmpFilePath} to ${bucket}/${key}`);

    function uploadFromStream(s3, bucket, key) {
      const pass = new stream.PassThrough();

      const params = {
        Bucket: bucket,
        Key: key,
        Body: pass
      };
      s3.upload(params, function(err, data) {
        debug('S3 upload done');
        if (err) {
          debug(err);
          reject(new VError(err, 'Upload failed'));
          return;
        }
        debug('Upload succeeded');
        debug(data);
        resolve();
      }).httpUploadProgress = (progress) => {
        debug(`S3 upload progress: ${progress}`);
      };

      return pass;
    }

    const inputStream = fs.createReadStream(backupTmpFilePath);
    const s3Stream = uploadFromStream(s3, bucket, key);
    inputStream.pipe(s3Stream);
  });
}
function uploadNewBackup ( s3 , backupTmpFilePath , bucket , key ) { return new Promise ( ( resolve , reject ) => { debug ( ` ${ backupTmpFilePath } ${ bucket } ${ key } ` ) ; function uploadFromStream ( s3 , bucket , key ) { const pass = new stream . PassThrough ( ) ; const params = { Bucket : bucket , Key : key , Body : pass } ; s3 . upload ( params , function ( err , data ) { debug ( 'S3 upload done' ) ; if ( err ) { debug ( err ) ; reject ( new VError ( err , 'Upload failed' ) ) ; return ; } debug ( 'Upload succeeded' ) ; debug ( data ) ; resolve ( ) ; } ) . httpUploadProgress = ( progress ) => { debug ( ` ${ progress } ` ) ; } ; return pass ; } const inputStream = fs . createReadStream ( backupTmpFilePath ) ; const s3Stream = uploadFromStream ( s3 , bucket , key ) ; inputStream . pipe ( s3Stream ) ; } ) ; }
Upload a backup file to an S3 bucket.

@param {any} s3 Object store client
@param {any} backupTmpFilePath Path of backup file to write.
@param {any} bucket Object store bucket name
@param {any} key Object store key name
@returns Promise
Upload a backup file to an S3 bucket .