Saturday, 15 April 2017

Naming files on users' upload

I want to save the file before a blog post is submitted. So here's what I did but I'm not sure this is the best way. User upload an image, I upload it to s3 bucket with this filename

const file_name = Date.now() + '-' + req.files.file.name + '-' ObjectID;

  • ObjectID is a bson id.

Then if the user click submit I pass the ObjectID to save the blog post.



via Jenny Mok

No comments:

Post a Comment