nathanpeck / s3-upload-stream

A Node.js module for streaming data to Amazon S3 via the multipart upload API
MIT License
347 stars 46 forks source link

Converting from s3-uploader to this lib #47

Open ORESoftware opened 7 years ago

ORESoftware commented 7 years ago

hey there!

streams ftw, I am converting some old code to streams, so I am going from require('s3-uploader') to require('s3-upload-stream')!

Our old code looks like this:


const Upload = require('s3-uploader')

const postImgUploader = new Upload(awsS3Bucket, {
  aws: {
    path: awsPath,
    region: awsRegion,
    acl: 'public-read',
    accessKeyId: accessKeyId,
    secretAccessKey: secretAccessKey
  },
  cleanup: {
    versions: true,
    original: true
  },
  versions: [{
    maxWidth: 720,
    maxHeight: 405,
    format: 'jpg',
    suffix: '-large'
  }, {
    maxWidth: 480,
    maxHeight: 270,
    format: 'jpg',
    suffix: '-medium'
  }, {
    maxWidth: 100,
    maxHeight: 100,
    format: 'jpg',
    suffix: '-square'
  }]
});

the response from S3 looks like this for the above code:

versions => [ { maxWidth: 720,
    maxHeight: 405,
    format: 'jpg',
    suffix: '-large',
    quality: 70,
    path: 'images/15cb156b-e07a-46b1-9dd3-c8432be3df98-large.jpg',
    width: 720,
    height: 370,
    awsImageAcl: 'public-read',
    etag: '"99bb229f7dcd2b11ea5fb791c28249d3"',
    key: 'images/82b803e2-a827-48d2-9985-ada7129f8ce1-large.jpg',
    url: 'https://s3.amazonaws.com/staging-lectal-media-assets/images/82b803e2-a827-48d2-9985-ada7129f8ce1-large.jpg' },
  { maxWidth: 480,
    maxHeight: 270,
    format: 'jpg',
    suffix: '-medium',
    quality: 70,
    path: 'images/15cb156b-e07a-46b1-9dd3-c8432be3df98-medium.jpg',
    width: 480,
    height: 247,
    awsImageAcl: 'public-read',
    etag: '"92c39e2b6ca49c70cb615477fd416c5c"',
    key: 'images/82b803e2-a827-48d2-9985-ada7129f8ce1-medium.jpg',
    url: 'https://s3.amazonaws.com/staging-lectal-media-assets/images/82b803e2-a827-48d2-9985-ada7129f8ce1-medium.jpg' },
  { maxWidth: 100,
    maxHeight: 100,
    format: 'jpg',
    suffix: '-square',
    quality: 70,
    path: 'images/15cb156b-e07a-46b1-9dd3-c8432be3df98-square.jpg',
    width: 100,
    height: 51,
    awsImageAcl: 'public-read',
    etag: '"2710c07b88a27e5eca383abfcb43ea36"',
    key: 'images/82b803e2-a827-48d2-9985-ada7129f8ce1-square.jpg',
    url: 'https://s3.amazonaws.com/staging-lectal-media-assets/images/82b803e2-a827-48d2-9985-ada7129f8ce1-square.jpg' } ]

when I use your module, with the following config:

function getUploadStrm() {

    return s3Stream.upload({
        Bucket: awsS3Bucket,
        Key: accessKeyId,
        ACL: 'public-read',
        StorageClass: 'REDUCED_REDUNDANCY',
        ContentType: 'binary/octet-stream'
    }, {});
}

I get this output:

detail =>  { Location: 'https://staging-lectal-media-assets.s3.amazonaws.com/AKIAIRNYI65C5VKWDEDQ',
  Bucket: 'staging-lectal-media-assets',
  Key: 'AKIAIRNYI65C5VKWDEDQ',
  ETag: '"d7165b042c4068477d03341ca75518e1-1"' }
detail =>  { Location: 'https://staging-lectal-media-assets.s3.amazonaws.com/AKIAIRNYI65C5VKWDEDQ',
  Bucket: 'staging-lectal-media-assets',
  Key: 'AKIAIRNYI65C5VKWDEDQ',
  ETag: '"e325f4cb98e4af408e60e421e37a4a27-1"' }
detail =>  { Location: 'https://staging-lectal-media-assets.s3.amazonaws.com/AKIAIRNYI65C5VKWDEDQ',
  Bucket: 'staging-lectal-media-assets',
  Key: 'AKIAIRNYI65C5VKWDEDQ',
  ETag: '"8a04422756e20eb9f93718422f11dad8-1"' }

I am wondering if you can help me get similar output to the output form the s3-uploader module - is there a way to configure s3-upload-stream to create URLs in that form?

Any help appreciated, thanks!

ORESoftware commented 7 years ago

definitely could use help with this if you have a moment, thanks

this question puts it more succinctly: http://stackoverflow.com/questions/42016773/uploading-images-to-s3-and-retrieving-unique-urls-for-images