Learn how to manage files using the Get Pronto SDK. This guide covers uploading, listing, retrieving, and deleting files.
File operations return a FileMetadata object with the following structure:
type FileMetadata = {
id: string;
name: string;
secureUrl: string;
secureThumbnailUrl: string;
rawUrl: string;
type: string;
rawType: string;
size: string;
rawSize: number;
updated: string;
rawUpdated: string;
folderId: string | null;
};Upload a file to your Get Pronto account. Works with both secret and public API keys.
upload(file: File | Buffer | string, options?: { filename?: string; mimeType?: string; folder?: string }): Promise<APIResponse<FileMetadata>>| Type | Description |
|---|---|
| File | Browser File object |
| Buffer | Node.js Buffer object |
| string | File path (Node.js), data URL, or remote URL |
| Option | Type | Description |
|---|---|---|
| filename | string | Custom filename for the uploaded file |
| mimeType | string | Override the file's MIME type |
| folder | string | Folder name to upload the file into |
// Upload from local file path
try {
const result = await client.files.upload("./path/to/image.jpg");
console.log("File uploaded:", result.data);
} catch (error) {
console.error("Upload failed:", error);
}
// Upload with custom filename
const result = await client.files.upload("./image.jpg", {
filename: "custom-name.jpg"
});// Upload from remote URL
try {
const result = await client.files.upload("https://example.com/image.jpg");
console.log("File uploaded:", result.data);
} catch (error) {
console.error("Upload failed:", error);
}Retrieve a paginated list of files in your account. Requires a secret API key.
list(options?: { page?: number; pageSize?: number; folder?: string }): Promise<APIResponse<PaginatedResponse<FileMetadata>>>| Option | Type | Description |
|---|---|---|
| page | number | Page number (default: 1) |
| pageSize | number | Items per page (default: 20, max: 100) |
| folder | string | Filter files by folder name |
// List files with default pagination
const response = await client.files.list();
console.log("Files:", response.data.files);
console.log("Pagination:", response.data.pagination);
// List with custom pagination
const response = await client.files.list({
page: 2,
pageSize: 50
});Retrieve metadata for a specific file by its ID. Requires a secret API key.
get(id: string): Promise<APIResponse<FileMetadata>>const fileId = "123e4567-e89b-12d3-a456-426614174000";
try {
const file = await client.files.get(fileId);
console.log("File metadata:", file);
} catch (error) {
console.error("Failed to get file:", error);
}Permanently delete a file from your account. Requires a secret API key.
delete(id: string): Promise<APIResponse<void>>const fileId = "123e4567-e89b-12d3-a456-426614174000";
try {
await client.files.delete(fileId);
console.log("File deleted successfully");
} catch (error) {
console.error("Failed to delete file:", error);
}The SDK throws errors when operations fail. Each error includes detailed information about what went wrong.
try {
const result = await client.files.upload(file);
} catch (error) {
if (error instanceof APIError) {
console.error("API Error:", error.message);
console.error("Status:", error.status);
console.error("Response:", error.body);
} else {
console.error("Unexpected error:", error);
}
}Continue exploring our documentation with these related topics: