lib/upload.js
function uploadFile(aws, bucketName, filePath, fileKey, headers) {
  const baseHeaderKeys = [
    'Cache-Control',
    'Content-Disposition',
    'Content-Encoding',
    'Content-Language',
    'Content-Type',
    'Expires',
    'Website-Redirect-Location'
  ];

  const fileBuffer = fs.readFileSync(filePath);

  const params = {
    Bucket: bucketName,
    Key: fileKey,
    Body: fileBuffer,
    ContentType: mime.lookup(filePath)
  };

  Object.keys(headers).forEach(h => {
    if (baseHeaderKeys.includes(h)) {
      params[h.replace('-', '')] = headers[h];
    } else {
      if (!params.Metadata) {
        params.Metadata = {};
      }
      params.Metadata[h] = headers[h];
    }
  });

  return aws.request('S3', 'putObject', params);
}
function uploadFile(aws, bucketName, filePath, fileKey, headers) {
  const baseHeaderKeys = [
    'Cache-Control',
    'Content-Disposition',
    'Content-Encoding',
    'Content-Language',
    'Content-Type',
    'Expires',
    'Website-Redirect-Location'
  ];

  const fileBuffer = fs.readFileSync(filePath);

  const params = {
    Bucket: bucketName,
    Key: fileKey,
    Body: fileBuffer,
    ContentType: mime.lookup(filePath)
  };

  Object.keys(headers).forEach(h => {
    if (baseHeaderKeys.includes(h)) {
      params[h.replace('-', '')] = headers[h];
    } else {
      if (!params.Metadata) {
        params.Metadata = {};
      }
      params.Metadata[h] = headers[h];
    }
  });

  return aws.request('S3', 'putObject', params);
}
function uploadFile ( aws , bucketName , filePath , fileKey , headers ) { const baseHeaderKeys = [ 'Cache-Control' , 'Content-Disposition' , 'Content-Encoding' , 'Content-Language' , 'Content-Type' , 'Expires' , 'Website-Redirect-Location' ] ; const fileBuffer = fs . readFileSync ( filePath ) ; const params = { Bucket : bucketName , Key : fileKey , Body : fileBuffer , ContentType : mime . lookup ( filePath ) } ; Object . keys ( headers ) . forEach ( h => { if ( baseHeaderKeys . includes ( h ) ) { params [ h . replace ( '-' , '' ) ] = headers [ h ] ; } else { if ( ! params . Metadata ) { params . Metadata = { } ; } params . Metadata [ h ] = headers [ h ] ; } } ) ; return aws . request ( 'S3' , 'putObject' , params ) ; }
Uploads a file to an S3 bucket
@param {Object} aws - AWS class
@param {string} bucketName - Name of bucket to be configured
@param {string} filePath - Full path to file to be uploaded
@param {string} clientRoot - Full path to the root directory of client files
Uploads a file to an S3 bucket