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;
filename: string;
mimetype: string;
size: number;
createdAt: string;
url: string;
};
Upload a file to your Get Pronto account.
upload(file: File | Buffer | string, options?: { filename?: string; mimeType?: string }): Promise<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 |
// Upload from local file path
try {
const result = await client.files.upload("./path/to/image.jpg");
console.log("File uploaded:", result.file);
} 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.file);
} catch (error) {
console.error("Upload failed:", error);
}
Retrieve a paginated list of files in your account.
list(options?: { page?: number; pageSize?: number }): Promise<PaginatedResponse<FileMetadata>>
Option | Type | Description |
---|---|---|
page | number | Page number (default: 1) |
pageSize | number | Items per page (default: 20, max: 100) |
// List files with default pagination
const response = await client.files.list();
console.log("Files:", response.files);
console.log("Pagination:", response.pagination);
// List with custom pagination
const response = await client.files.list({
page: 2,
pageSize: 50
});
Retrieve metadata for a specific file by its ID.
get(id: string): Promise<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.
delete(id: string): Promise<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: