I am using GridFsOperations API of spring-data for mongodb to store large files in chunks in the db. Here is my code:
@Autowired
private GridFsOperations gridOperation;
public String save(InputStream inputStream, String contentType, String filename) {
...
GridFSFile file = gridOperation.store(inputStream, filename, metaData);
return file.getId().toString();
}
The code works fine but it always stores files in collections starting with prefix “fs”, which is the default in mongodb. Is there a way to specify a different prefix so that I can have different files and chunks for different kinds of files to be stored?
EDIT: additional question
How do I specify the chunk size? Is it advisable to have different chunk sizes for different kinds of files, for example – 2 mb for image files and 10 mb for video files?
I got solutions to both my questions (configure chunk sizes in my code and use different prefixes) using GridFS and GridFSInputFile classes instead of GridFSTemplate or GridFSOperations.
I still want to know if its advisable to have different chunk sizes.
For anybody who may want to know, here is the code snippet: