您的位置:首页 > 数据库 > Mongodb

ExpressJS File Uploading – GridFS – MongoDB

2016-01-08 10:39 204 查看
n this blog post we will see how to handle multipart data/file uploading with expressjs. Save files to mongodb using GridFS and rending files.

To handle file uploads in express, i will use the library located at https://github.com/expressjs/multer

In your express app.js file

The above code catches all multipart data, fileuploads automatically and stores the file to ‘uploads/’ folder. So its super easy. So basically if you have a form tag, with its action pointed to a express route. Fileupload server handling is taken care automatically and all file move to ‘uploads’ folder.

Now let’s see how to save uploaded file to mongodb. Detailed explanation of using gridfs here

Suppose the file upload URL is http://127.0.0.1:3000/upload
Now let’s see how to view image file uploaded in mongo

If URL to view files is http://127.0.0.1:3000/file/mongo_id
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: