Apstrata relieves you from managing a file system or a database: using the store that is automatically associated to your Apstrata application, you can persist data of different types into documents. Documents have a key/value pairs structure, where the key is a field name and the value can have one of the following types: string, numeric, text, date, geospatial and notably file.
To upload a file to your store, simply invoke the SaveDocument API and provide it with a document that contains a file. Apstrata documents have the predefined "apsdb_attachments" field that you can use to attach one or multiple files but you can also specify your own fields, which will require you to define a schema. To download your file, simply use the GetFile API, passing the names of the field and the attached file you would like to retrieve.
Example 1: upload the player's picture to his persisted profile
You are currently implementing the next "unhappy poultry" mobile game and you think that it is cool to allow your players to upload a picture of themselves (or any other picture) to be used as an avatar in the game. Let us see how to do this using Apstrata. In the below example, we consider that we already created a profile document ("gangsta_profile") for a player named "gangsta", so we will issue a request to update this document by attaching the profile picture to the "apsdb_attachment" field.
Example 2: download the player's picture to his device
Let us see now how you can download the profile picture back to the device:
Example 3: save the player's picture only if smaller than 500Kb
Based on example 1 above, let us assume that you want to avoid excessive storage consumption and therefore, limit the size of the player picture to 500kb max. Hence, you need to check the size of the file before saving it into a document in your store. A solution is to do this in your Apstrata back-end, using a server-side script.