Turistforeningen/node-s3-uploader

Idea: post-resize hook / event

Opened this issue · 1 comments

Just want to pitch this idea here.
I'd like to optimize the resized images before they are uploaded.
What do you think about adding the possibility to let the user do stuff (could be anything) after the images are resized?

Interesting idea Anthony, here is a concept for how this could work:

function preUploadHandler(cb, results) {
  // results.versions
};

new Uploader({..., hooks: { preUpload: preUploadHandler }});

With the corresponding change in src/index.coffee:

Image.prototype.start = (cb) ->
  auto
    metadata: @getMetadata.bind(@, @src)
    dest: @getDest.bind(@)
    versions: ['metadata', @resizeVersions.bind(@)]
    preupload: ['versions', @opts.hooks.preupload]
    uploads: ['preupload', 'dest', @uploadVersions.bind(@)]
    cleanup: ['uploads', @removeVersions.bind(@)]
  , (err, results) ->
    cb err, results.uploads, results.metadata

I have to think a little more if this is something s3-uploader should do, and if this is the correct approach.