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
To handle file uploads in express, i will use the library located at https://github.com/expressjs/multer
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
If URL to view files is http://127.0.0.1:3000/file/mongo_id
相关文章推荐
- mongodb的基本配置
- MongoDB在Linux下安装和启动和配置
- Linux下MongoDB的安装、配置、启动
- window平台安装 MongoDB
- mongoose封装管理mongodb的公共模块
- MongoDB数据逻辑结构
- MongoDB在Windows 平台的安装
- 初识 MongoDB
- 【MongoDB】CentOS上安装MongoDB
- MongoDB快速入门笔记
- Ubuntu系统中安装MongoDB及其启动命令mongod的教程
- 搭建高可用的MongoDB集群
- mysql与mongoDB语法对比
- mongodb Replica Sets副本集与读写分离
- mongoDB系列之(三):mongoDB 分片
- mongoDB系列之(三):mongoDB 分片
- Mongodb带验证的主从复制架构
- Ubuntu系统中安装MongoDB及其启动命令mongod的教程
- 基于linux的mongodb3.2副本集+分片集群搭建
- 基于C#的MongoDB数据库开发应用(2)--MongoDB数据库的C#开发