Skip to main content

FileSystem

GET /file-system

Get file system structure

Required scope: file:read

Parameters

NameTypeRequiredSourceDescription
clientIdstringqueryClient ID for the Foundry world
pathstringqueryThe path to retrieve (relative to source)
sourcestringqueryThe source directory to use (data, systems, modules, etc.)
recursivebooleanqueryWhether to recursively list all subdirectories
userIdstringquery, bodyFoundry user ID or username to scope permissions (omit for GM-level access)

Returns

object - File system structure with files and directories

Try It Out

Code Examples

const baseUrl = 'http://localhost:3010';
const path = '/file-system';
const params = {
clientId: 'fvtt_099ad17ea199e7e3',
source: 'data',
recursive: 'false'
};
const queryString = new URLSearchParams(params).toString();
const url = `${baseUrl}${path}?${queryString}`;

const response = await fetch(url, {
method: 'GET',
headers: {
'x-api-key': 'your-api-key-here'
}
});
const data = await response.json();
console.log(data);

Response

Status: 200

{
"type": "file-system-result",
"requestId": "file-system_1778896436806",
"success": true,
"path": "",
"source": "data",
"results": [
0: {
"name": "assets",
"path": "assets",
"type": "directory"
},
1: {
"name": "maps",
"path": "maps",
"type": "directory"
},
2: {
"name": "modules",
"path": "modules",
"type": "directory"
},
3: {
"name": "moulinette",
"path": "moulinette",
"type": "directory"
},
4: {
"name": "obsidian-files",
"path": "obsidian-files",
"type": "directory"
},
5: {
"name": "rest-api-tests",
"path": "rest-api-tests",
"type": "directory"
},
6: {
"name": "systems",
"path": "systems",
"type": "directory"
},
7: {
"name": "tokenizer",
"path": "tokenizer",
"type": "directory"
},
8: {
"name": "uploaded-chat-media",
"path": "uploaded-chat-media",
"type": "directory"
},
9: {
"name": "worlds",
"path": "worlds",
"type": "directory"
},
10: {
"name": "flooded-cave-test.webp",
"path": "flooded-cave-test.webp",
"type": "file"
}
],
"recursive": false
}

GET /download

Download a file from Foundry's file system

Required scope: file:read

Parameters

NameTypeRequiredSourceDescription
clientIdstringqueryClient ID for the Foundry world
pathstringqueryThe full path to the file to download
sourcestringqueryThe source directory to use (data, systems, modules, etc.)
formatstringqueryThe format to return the file in (binary, base64)
userIdstringquery, bodyFoundry user ID or username to scope permissions (omit for GM-level access)

Returns

object - File contents in the requested format

Try It Out

Code Examples

const baseUrl = 'http://localhost:3010';
const path = '/download';
const params = {
clientId: 'fvtt_099ad17ea199e7e3',
path: 'rest-api-tests/test-file.txt',
source: 'data',
format: 'base64'
};
const queryString = new URLSearchParams(params).toString();
const url = `${baseUrl}${path}?${queryString}`;

const response = await fetch(url, {
method: 'GET',
headers: {
'x-api-key': 'your-api-key-here'
}
});
const data = await response.json();
console.log(data);

Response

Status: 200

{
"fileData": "data:text/plain;base64,SGVsbG8gZnJvbSBSRVNUIEFQSSB0ZXN0IQ==",
"filename": "test-file.txt",
"mimeType": "text/plain",
"path": "rest-api-tests/test-file.txt",
"requestId": "download-file_1778896436810",
"success": true,
"type": "download-file-result"
}

POST /upload

Upload a file to Foundry's file system (handles both base64 and binary data)

Required scope: file:write

Parameters

NameTypeRequiredSourceDescription
clientIdstringqueryClient ID for the Foundry world
pathstringquery, bodyThe directory path to upload to
filenamestringquery, bodyThe filename to save as
sourcestringquery, bodyThe source directory to use (data, systems, modules, etc.)
mimeTypestringquery, bodyThe MIME type of the file
overwritebooleanquery, bodyWhether to overwrite an existing file
fileDatastringbodyBase64 encoded file data (if sending as JSON) 250MB limit
userIdstringquery, bodyFoundry user ID or username to scope permissions (omit for GM-level access)

Returns

object - Result of the file upload operation

Try It Out

Code Examples

const baseUrl = 'http://localhost:3010';
const path = '/upload';
const params = {
clientId: 'fvtt_099ad17ea199e7e3',
path: 'rest-api-tests',
source: 'data',
filename: 'test-file.txt',
mimeType: 'text/plain'
};
const queryString = new URLSearchParams(params).toString();
const url = `${baseUrl}${path}?${queryString}`;

const response = await fetch(url, {
method: 'POST',
headers: {
'x-api-key': 'your-api-key-here',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"fileData": "data:text/plain;base64,SGVsbG8gZnJvbSBSRVNUIEFQSSB0ZXN0IQ==",
"mimeType": "text/plain",
"overwrite": true
})
});
const data = await response.json();
console.log(data);

Response

Status: 200

{
"type": "upload-file-result",
"requestId": "upload-file_1778896436792",
"success": true,
"path": "rest-api-tests/test-file.txt"
}