anacronw / multer-s3

multer storage engine for amazon s3
MIT License
660 stars 190 forks source link

Add metadata function #22

Closed briandonahue closed 8 years ago

briandonahue commented 8 years ago

I added another callback function to the options for creating metadata for the s3 object. For example you could use the below (ES6 example) to add all the fields from the body as metadata. I found that extending a plain object (using Object.assign here) was necessary as passing req.body directly throws an error, I didn't dig too far into that, I'm assuming it's a not just a hash and aws didn't like it.

var opts = {
    bucket: config.originalsBucket,
    secretAccessKey: config.awsSecretAccessKey,
    accessKeyId: config.awsAccessKeyId,
    region: 'us-east-1',
    metadata: function (req, file, cb) {
      cb(null, Object.assign({}, req.body));
    }
  };
anacronw commented 8 years ago

26 will be using the aws-sdk directly for options, so we don't have to reinvent the wheel.

Thanks!

briandonahue commented 8 years ago

I'm not understanding how I would pass in metadata per file, though? I see that #26 allows you to pass in your own s3 instance with options, but I need to send metadata along with each file that is uploaded, based on that file/request. Maybe I'm missing it, but it doesn't seem #26 solves that problem?

LinusU commented 8 years ago

I think that pull request might still be relevant, we have changed the code quite a bit since it was opened though so it will need a rebase with a few changes. Could you look at #27 and model it after that? Note the added documentation and the usage of setImmediate :ok_hand:

briandonahue commented 8 years ago

Will add the documentation, not finished yet...

briandonahue commented 8 years ago

@LinusU @badunk OK, I think this is all set. Let me know what you think.

LinusU commented 8 years ago

Looking awesome :raised_hands:

LGTM from me

briandonahue commented 8 years ago

@badunk Just bumping this. Any thoughts, or is it good to merge?

LinusU commented 8 years ago

🎉