Skip to main content

Upload Model

Warlock is shipped with Upload model to store the uploaded files in the database.

When a file is uploaded, it will be stored in the database using the Upload model.

Stored data

The following schema is stored inside the uploads collection for each uploaded file:

{
"hash": "string",
"name": "string",
"size": "number",
"extension": "string",
"path": "string",
"directory": "string",
"mimeType": "string"
}

If the uploaded file is an image, then width and height will be stored as well.

The size is stored in bytes.

The file name will be stored as-is from the upload request, this is has nothing related to whether if the uploaded file is stored with its name or randomly.

Upload output

When the upload model is sent to the response, the UploadOutput will return the following data:

{
"id": "string",
"hash": "string",
"name": "string",
"size": "number",
"extension": "string",
"url": "string",
"mimeType": "string",
"width": "number",
"height": "number"
}

The id and hash are both the same, so you can use either of them.

The url is the full URL to the uploaded file, it's generated by passing the file path the uploadsUrl function.

The width and height are only returned if the uploaded file is an image.