The Storage API provides comprehensive file management capabilities within the user's dedicated storage space (/mnt/swiftor/users/{username}/storage
). It allows for listing, uploading, downloading, creating, deleting, and moving files and folders, as well as reading and writing text file content.
Path Handling
my_folder/my_file.txt
)...
) and access to restricted directories.GET /
) Retrieves a hierarchical list of all files and folders within the user's storage space, including hidden items (those starting with .
).
Returns an object containing a files
array. Each element represents a file or folder with properties like id
(relative path), name
, isDir
, modDate
, size
(for files), parentId
, childrenIds
(for folders), and isHidden
.
{
"files": [
{
"id": "root",
"name": "/",
"isDir": true,
"modDate": 1678886400000,
"childrenIds": ["my_folder", "my_file.txt", ".hidden_folder"]
},
{
"id": "my_folder",
"name": "my_folder",
"isDir": true,
"modDate": 1678886401000,
"parentId": "root",
"childrenIds": ["my_folder/nested_file.log"],
"isHidden": false
},
{
"id": ".hidden_folder",
"name": ".hidden_folder",
"isDir": true,
"modDate": 1678886403000,
"parentId": "root",
"childrenIds": [],
"isHidden": true
},
{
"id": "my_file.txt",
"name": "my_file.txt",
"isDir": false,
"modDate": 1678886402000,
"size": 1024,
"parentId": "root",
"isHidden": false
},
{
"id": "my_folder/nested_file.log",
"name": "nested_file.log",
"isDir": false,
"modDate": 1678886404000,
"size": 512,
"parentId": "my_folder",
"isHidden": false
}
// ... other files/folders
]
}
POST /upload/{folder_path:path}
) Uploads one or more files to the specified folder path within the user's storage. If the target folder path doesn't exist, it will be created.
{folder_path}
: The relative path of the destination folder (e.g., my_folder
or existing_folder/new_subfolder
). Use .
for the root directory.multipart/form-data
containing one or more files.{
"success": true,
"files": [
{ "name": "uploaded_file1.zip", "size": 20480, "modDate": 1678886405000 },
{ "name": "image.png", "size": 5120, "modDate": 1678886406000 }
]
}
POST /create-folder/{folder_path:path}
) Creates a new folder at the specified path. Parent directories will be created if they don't exist.
{folder_path}
: The relative path of the folder to create (e.g., new_data_folder
or existing_folder/another_level
).{
"success": true,
"folder": {
"path": "new_data_folder",
"modDate": 1678886407000
}
}
POST /create-file/{file_path:path}
) Creates a new, empty text file (or a file with initial content) at the specified path. Parent directories will be created if they don't exist.
{file_path}
: The relative path of the file to create (e.g., config.json
or my_folder/notes.txt
).{"content": "Initial file text here"}
{"content": ""}
.{
"success": true,
"file": {
"path": "my_folder/notes.txt",
"modDate": 1678886408000,
"size": 21 // Size of the initial content
}
}
DELETE /{path:path}
) Deletes a file or folder.
{path}
: The relative path of the file or folder to delete.permanent
(boolean, optional): true
, the item is deleted permanently.false
or omitted, the item is moved to the user's trash directory (/mnt/swiftor/users/{username}/trash
), preserving its relative path.Permanent Deletion
Setting permanent=true
bypasses the trash and cannot be undone.
{
"success": true
}
POST /move
) Moves one or more files or folders to a destination folder.
{
"source_paths": ["file_to_move.txt", "folder_to_move"],
"destination": "target_folder/sub_folder"
}
source_paths
(List[string], required): A list of relative paths of items to move.destination
(string, required): The relative path of the destination folder. It will be created if it doesn't exist.{
"success": true,
"moved": ["file_to_move.txt", "folder_to_move"] // List of paths successfully moved
}
GET /download/{path:path}
) Downloads a single file or an entire folder (as a ZIP archive).
{path}
: The relative path of the file or folder to download.Content-Disposition
set to the filename and Content-Type: application/octet-stream
.StreamingResponse
with Content-Type: application/zip
. The Content-Disposition
filename will be {folder_name}.zip
.The raw file data or ZIP archive data.
POST /download-multiple
) Downloads multiple specified files and/or folders as a single ZIP archive.
[
"file1.txt",
"important_folder",
"another_folder/data.csv"
]
StreamingResponse
with Content-Type: application/zip
.Content-Disposition
filename will be files_{timestamp}.zip
.The raw ZIP archive data.
GET /{file_path:path}
) Retrieves the text content of a specified file.
{file_path}
: The relative path of the text file to read.{
"content": "The text content of the file.\nWith multiple lines."
}
404 Not Found
: If the file doesn't exist.400 Bad Request
: If the path points to a folder or the file is not UTF-8 decodable (binary).PUT /{file_path:path}
) Writes or overwrites the text content of a specified file. Parent directories will be created if they don't exist.
{file_path}
: The relative path of the text file to write.{"content": "New file content to save."}
(The content
key is required).{
"success": true,
"file": {
"path": "config.json",
"size": 512,
"modDate": 1678886409000
}
}