Re: Spring GridFsOperations (Java) API for storing in mongo with a custom prefix

169 views
Skip to first unread message

Louisa Berger

unread,
Oct 15, 2012, 5:24:27 PM10/15/12
to mongod...@googlegroups.com
To change the default prefix, you can pass a different prefix as the second param into the GridFS constructor :

GridFS g = new GridFS( database, "new_prefix").


The default chunk size is 256k. To specify the chunk size, you can call the setChunkSize method on the GridFSInputFile class before uploading the file.

The default chunk size was determined through testing the size for a variety of applications, and will work well for most applications. 


On Saturday, October 6, 2012 10:17:13 PM UTC-4, Rahul Jaiswal wrote:

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, 1 mb for image files and 10 mb for video files?

Thanks in advance

Reply all
Reply to author
Forward
0 new messages