Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to state during event flow #77

Closed
longieirl opened this issue Nov 19, 2014 · 4 comments
Closed

Access to state during event flow #77

longieirl opened this issue Nov 19, 2014 · 4 comments

Comments

@longieirl
Copy link

Hi,

First off, great plugin, using it for a POC and does what it says on the tin!

Just a question in relation to how I can access output generated as part of the multer step or to pass objects into it!

For example;

  1. User posts many files to an api/upload endpoint
  2. Mutler kicks in and as part of the onFileUploadComplete event, triggers the images to be compressed
  3. If all the events in Multer are successful, the user receives a valid 200 with a JSON response
  4. Mongdb is updated with the results and images are both stored in static directory and in database as a base64 string

However, as part of the onFileUploadComplete event i need the output generated to be added to an existing table or at least added to already created object that will be saved when Multer is completed.

Your advice would be appreciated on how to either store the compressed image to the db by passing in the new mongo model during the onFileUploadComplete step or by returning the compressed image so that it can be done outside of the Mutler tasks.

J

@longieirl
Copy link
Author

Assuming best practice here is to just populate the request object req.imgs in onFileUploadComplete where imgs is just a store with the base64 representation of the image that I can then read in the app.post function when multer is complete...this will will allow the mongodb functionality to be all in one place.

@longieirl
Copy link
Author

Got something working, small working POC at https://github.com/longieirl/File-Upload-NodeJS-Mongo/

@jpfluger
Copy link
Contributor

jpfluger commented May 1, 2015

Your code works, using Imagemin and Base64. MongoDB's best practice is to use GridFS. Here's a conversation that might help.

@LinusU
Copy link
Member

LinusU commented Jul 18, 2015

I believe that the correct way to implement this now that 1.0.0 is released is to implement a GridFS storage engine.

Documentation:
https://github.com/expressjs/multer/blob/master/StorageEngine.md

@LinusU LinusU closed this as completed Jul 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants