10gen Filesystems
apidocsThe 10gen environment uses two filesystems:
- 10gen GridFS - An infinitely scaleable distributed filesystem that uses the Mongo database for storage.
- Source Code Filesystem (SCF) - A small, conventional filesystem for application source code and other static objects (JS, JXP, CSS, HTML, small images) managed via your Git repository. In general, you should store only system "code" files and such in this filesystem.
10gen Grid Filesystem (GridFS)
GridFS is a global file store for your application. 10gen’s philosophy is to store files in the database rather than in a separate global file system: GridFS is a thin, simple layer atop the Mongo db.The /admin/ menu includes a Files option for browsing and uploading files.
Files are stored as database objects in the _files collection. The actual file content is stored as a series of data chunks in the _chunks collection. Usually, you don't have to directly interact with _chunks. The 10gen library functions handle that for you.
Uploading GridFS Files
Useinput type="file" in your HTML form to upload a file. In JXP files, you can fetch the file object from the HTTP request with request.getFile(name), then save it to the database.
<%
var aImage = request.getFile( "image" );
if ( aImage )
db._files.save( aImage );
%>
...
<form method="POST" enctype="multipart/form-data" >
image: <input name="image" type="file" /><br>
<input type="submit" value="Upload File" />
</form>
Downloading GridFS Files
Your code may invoke theresponse.sendFile(file) method to have the app server transmit a file as an HTTP response to the user.
Additionally files may be downloaded through the URL
/~~/f?id=<id of the file>
or
/~~/f/<filename>.
Access Control
Note that by default, GridFS files are publicly accessible (if one knows the name or id at least) at the URL /~~/f/. You can restrict this when needed; contact us in the forums for more information.
Source Code Filesystem (SCF)
UseopenFile() to open a file for reading.
var theFile = openFile( filename );
if ( theFile.exists() ){
var data = theFile.getDataAsString();
}
Deleting SCF Files
UseopenFile(name).remove(recurse) to delete a file. When true, recurse removes all files under the (directory) name.
For more information see core.file.file.
