Skip to content

File saved/retrieved/deleted Project using Java, Spring Boot, MongoDB database and GridFSBucket

Notifications You must be signed in to change notification settings

kmjenniferng/java-spring-boot-mongodb-gridfsbucket

Repository files navigation

Binary File saved/retrieved/deleted using Java, Spring Boot, MongoDB, GridFsBucket

The purpose of this project is to create 3 RESTful APIs to perform the following actions in MongoDB database.

  1. Save a file
  2. Retrieve a file
  3. Delete a file

MongoDB provides GridFS for storing and retrieving files larger than 16MB. GridFS stores large binary files by breaking the files into smaller files called chunks and saving them in MongoDB. GridFS uses two collections called fs.files and fs.chunks to save a file into a database. The fs.chunks collection contains the binary file broken up into 255k chunks. The fs.files collection contains the metadata for the document.

GridFS Structure

Example

Each document in the fs.files collection is associated with a set of documents in the fs.chunks collection. The fs.chunks documents are numbered from 0 to n with binary data for the chunk stored in the data field. Each document in fs.files has its own _id and _id is related to files_id in fs.chunks. The following is the chunk associated with the document ObjectId 61a137e79375ad646308ca9c.

Instructions on running tests using POSTMAN

  1. Save a file

HTTP:POST localhost:8080/save/{filename}

Headers: Key = Content-Type, Value = application/json

Expected test result: file will be saved into MongoDB database.

Example: HTTP:POST localhost:8080/save/bear.jpg

  1. Retrieve a file

HTTP:GET localhost:8080/retrieve/{filename}

Headers: Key = Content-Type, Value = application/json

Expected test result: file will be retrieved from MongoDB database and saved it into "C:\Users\hk_je\Downloads\mongodb_gridfs_template_test\tmp" folder

  1. Delete a file

HTTP:DELETE: localhost:8080/delete/{filename}

Headers: Key = Content-Type, Value = application/json

Expected test result: file will be deleted from MongoDB database.

About

File saved/retrieved/deleted Project using Java, Spring Boot, MongoDB database and GridFSBucket

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages