GridFS does not store files as a structure, such as a file system hierarchy. Thus, there is no path associated with saved files. But you can add the path field manually.
public ObjectId saveFile(InputStream inputStream, String filename, String folder) {
GridFSInputFile gInputFile = gridfs.createFile(inputStream, filename);
gInputFile.put("path", folder);
gInputFile.save();
return ObjectId.massageToObjectId( gInputFile.getId() );
}
Now all files will have a path attribute.
source
share