SpringData MongoDB GridFsTemplate to save, retrieve, delete binary files (Image, Text files)
MongoDB provides GridFS for storing and retrieving large files with size limit of 16MB. So in the tutorial, JavaSampleApproach will show you how to work with SpringData Mongo GridFsTemplate to save, retrieve, delete binary files (Image, Text files).
Related posts:
- Bootstrap Image + MongoDB GridFsTemplate + SpringBoot RestAPI
- Spring MongoOperations to access MongoDB
- MongoDB – Model One-to-One, One-to-Many Relationships Embedded Documents | SpringBoot
I. Technologies
– Java: 1.8
– Maven: 3.3.9
– Spring Tool Suite: Version 3.8.4.RELEASE
– Spring Boot: 1.5.7.RELEASE
– MongoDB: version v3.4.9
II. SpringData Mongo GridFsTemplate
SpringData MongoDb provides GridFsTemplate
class to work with GridFs file, details:
public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver {
...
}
GridFsTemplate
implement interface GridFsOperations
that is the collection of operations to store and read files from MongoDB GridFS.
For convenient working, SpringBoot provides spring-boot-starter-data-mongodb
dependency that is the collection of {mongodb-driver
, spring-data-mongodb
}.
III. Practice
In the tutorial, we create a SpringBoot project as below:
Step to do:
- Create SpringBoot project
- Configure GridFsTemplate
- Implement RestAPIs to work with GridFs files
- Run & check results
1. Create SpringBoot project
More at:
Top comments (0)