File access in Foxx
ArangoDB is primarily a database. In most cases the best place to store datais therefore inside the database, not on the file system.
The most flexible way to serve files in your Foxx service is to simplypass them through in your router usingthe andthe response object’s method:
While allowing for greater control of how the file should be sent tothe client and who should be able to access it,doing this for all your static assets can get tedious.
Alternatively you can specify file assets that should be served by yourFoxx service directly in the using the attribute:
The service folder itself is considered an implementation artefact andmay be discarded and replaced without warning.ArangoDB maintains a canonical copy of each service internally todetect missing or damaged services and restore them automatically.
Writing to files outside the service folder introduces external state. Ina cluster this will result in Coordinators no longer being interchangeable.
However in some cases it may be feasible to store smaller files directly inArangoDB documents by using a separate collection.
Due to the way ArangoDB stores documents internally, you should not storefile contents alongside other attributes that might be updated independently.Additionally, large file sizes will impact performance for operationsinvolving the document and may affect overall database performance.
In production, you should avoid storing any files in ArangoDB or handling fileuploads in Foxx. The following example will work for moderate amounts of smallfiles but is not recommended for large files or frequent uploads ormodifications.
To store files in a document you can simply convert the file contentsas a to a base64-encoded string: