File Storage
MockServer provides an in-memory file store accessible through four control-plane endpoints. You can upload any named file — text, JSON, binary, certificates — and then reference it by name in response templates or retrieve it directly. All stored files are cleared when MockServer is reset.
Typical use cases include uploading binary fixtures too large to embed in expectations, providing certificate files to response templates, and sharing test assets across multiple test classes without touching the filesystem.
Store a file
Send a PUT request to /mockserver/files/store. The request body must contain name and content fields. Set base64 to true when uploading binary content.
| Field | Type | Required | Description |
|---|---|---|---|
| name | string | yes | Unique name for the file. Storing a file with an existing name overwrites it. |
| content | string | yes | File content as a UTF-8 string, or as a Base64-encoded string when base64 is true. |
| base64 | boolean | no | When true, the content value is decoded from Base64 before storage. Defaults to false. |
Store a text file
PUT /mockserver/files/store HTTP/1.1
Content-Type: application/json
{
"name": "response-body.json",
"content": "{\"status\":\"ok\"}"
}
Response (201 Created):
{"name":"response-body.json","size":15}
Store a binary file
PUT /mockserver/files/store HTTP/1.1
Content-Type: application/json
{
"name": "logo.png",
"content": "iVBORw0KGgo...",
"base64": true
}
Retrieve a file
Send a PUT request to /mockserver/files/retrieve with the file name. The response body is the raw file content (bytes), not a JSON wrapper.
PUT /mockserver/files/retrieve HTTP/1.1
Content-Type: application/json
{"name": "response-body.json"}
Response (200 OK) — raw file bytes:
{"status":"ok"}
Returns 404 Not Found if no file with that name exists.
List stored files
Send a PUT request to /mockserver/files/list with an empty body. The response is a JSON array of file names.
PUT /mockserver/files/list HTTP/1.1
Response (200 OK):
["response-body.json","logo.png"]
The order of file names in the response is not guaranteed — it does not necessarily reflect the order in which files were stored. If you need a stable order, sort the returned array client-side.
Delete a file
Send a PUT request to /mockserver/files/delete with the file name. Returns 200 OK on success or 404 Not Found if the file does not exist.
PUT /mockserver/files/delete HTTP/1.1
Content-Type: application/json
{"name": "response-body.json"}
Lifecycle
- All stored files are held in-memory only — they are not written to disk.
- Files are cleared when MockServer is reset (PUT /mockserver/reset). Re-upload files after a reset if needed.
- Storing a file with a name that already exists overwrites the previous content.
- There is no size limit enforced per file, but total storage is bounded by available JVM heap.
Example usage
# Store a JSON fixture
curl -s -X PUT http://localhost:1080/mockserver/files/store \
-H 'Content-Type: application/json' \
-d '{"name":"user.json","content":"{\"id\":1,\"name\":\"Alice\"}"}'
# List stored files
curl -s -X PUT http://localhost:1080/mockserver/files/list
# Retrieve the file
curl -s -X PUT http://localhost:1080/mockserver/files/retrieve \
-H 'Content-Type: application/json' \
-d '{"name":"user.json"}'
# Delete the file
curl -s -X PUT http://localhost:1080/mockserver/files/delete \
-H 'Content-Type: application/json' \
-d '{"name":"user.json"}'
Related Pages
- CRUD Data Store — a stateful keyed data store for mocking create, read, update, and delete APIs
- Persisting Expectations — save and reload expectations using the files managed here