Skip to content

A developer-friendly bucket system powered by MongoDB GridFS πŸ—„οΈ. Store, fetch, and manage large files seamlessly πŸš€ - simple, scalable, and open-source. 🌐

Notifications You must be signed in to change notification settings

vikashkrdeveloper/MongoGridFS-FilesBucket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Welcome to the MongoGridFS Files Bucket

This is a simple implementation of a file storage system using MongoDB's GridFS. It allows you to store files in a MongoDB database and retrieve them later.

Installation

To clone this repository, run the following command:

git clone https://github.com/vikashkrdeveloper/MongoGridFS-FilesBucket.git

Then check into the cloned repository:

cd MongoGridFS-FilesBucket

After that, install the required dependencies:

npm install

set the environment variables in a .env file in the root directory of the project. The following environment variables are required:

MONGO_URI=mongodb://localhost:27017/files-bucket
PORT=8000

And finally, start the server:

npm start
# Output
```bash
$ node ./bin/www

Connected to database: gridfs
Base URL:http://localhost:8000

Usage

To upload a file, send a POST request to the /upload/image endpoint with the file you want to upload. The file should be sent as a form-data request with the key file and caption as a string.

curl -X POST -F "file=@/path/to/file.jpg" -F "caption=This is a caption" http://localhost:8000/upload/image

To retrieve a file, send a GET request to the /get-image/:filename endpoint with the filename of the file you want to retrieve.

The server is running on port 8000. You can now test the API endpoints using Postman or any other API testing tool.

API Endpoints

The following are the API endpoints available in the application:

Method Endpoint Description
POST /upload/image Upload an image file
GET /get-image/:filename Retrieve an image file
GET /get-all-images Retrieve all images
POST /image/delete/:id Delete an image
GET /image/recent Fetch most recent image
POST /multiple/image/upload Upload multiple files
GET /get-image/:filename Fetch a particular image and render on browser
DELETE /file/del/:id Delete a particular file by an ID

Built With

  • Node.js - JavaScript runtime
  • Express - Web framework for Node.js
  • MongoDB - NoSQL database
  • GridFS - MongoDB's file storage system
  • Multer - Middleware for handling multipart/form-data
  • Multer GridFS Storage - Multer storage engine for GridFS
  • Mongoose - MongoDB object modeling tool
  • Dotenv - Module that loads environment variables from a .env file into process.env
  • Cors - Middleware for enabling CORS with various options
  • Body-parser - Middleware for parsing incoming request bodies
  • Morgan - HTTP request logger middleware
  • Method-override - Middleware for overriding HTTP methods
  • Debug - Tiny debugging utility
  • Bluebird - Promise library
  • Jade - Template engine for Express
  • Http-errors - Create HTTP errors
  • Cookie-parser - Parse cookie headers

File Structure

The application is structured as follows:

MongoGridFS-FilesBucket/
β”œβ”€β”€ bin/
β”‚   └── www
β”œβ”€β”€ public/
|   └── stylesheets/
|       └── style.css
β”œβ”€β”€ routes/
|   └── image.js
β”œβ”€β”€ views/
|   β”œβ”€β”€ error.jade
|   β”œβ”€β”€ index.jade
|   └── layout.jade
β”œβ”€β”€ controllers/
|   └── imageController.js
β”œβ”€β”€ helpers/
|   └── response-objects.js
β”œβ”€β”€ models/
|   β”œβ”€β”€ image.js
|   β”œβ”€β”€ pdf.js
|   └── video.js
β”œβ”€β”€ .env
β”œβ”€β”€ .gitignore
β”œβ”€β”€ app.js
β”œβ”€β”€ config.js
β”œβ”€β”€ package-lock.json
β”œβ”€β”€ package.json
└── README.md

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A developer-friendly bucket system powered by MongoDB GridFS πŸ—„οΈ. Store, fetch, and manage large files seamlessly πŸš€ - simple, scalable, and open-source. 🌐

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published