Given an inputstream, a string for the filename, and a string for the path how do I store the file in GridFS using Java? Right now I have it saving without the path:
public ObjectId saveFile(InputStream inputStream, String filename, String folder) {
GridFSInputFile gInputFile = gridfs.createFile(inputStream, filename);
gInputFile.save();
return ObjectId.massageToObjectId( gInputFile.getId() );
}
GridFS does not store files as a structure like file system hierarchy. So there isn’t any path associated with stored files. But you can add a path field manually.
Now all files will have ‘path’ attribute.