Documentation

File Operations

Learn how to manage files using the Get Pronto SDK. This guide covers uploading, listing, retrieving, and deleting files.

Available Methods

  • Upload File - Upload a file to your Get Pronto account. Works with both secret and public API keys.
  • List Files - Retrieve a paginated list of files in your account. Requires a secret API key.
  • Get File - Retrieve metadata for a specific file by its ID. Requires a secret API key.
  • Delete File - Permanently delete a file from your account. Requires a secret API key.

File Metadata

File operations return a FileMetadata object with the following structure:

typescript
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 File

Upload a file to your Get Pronto account. Works with both secret and public API keys.

Method Signature

typescript
upload(file: File | Buffer | string, options?: { filename?: string; mimeType?: string; folder?: string }): Promise<APIResponse<FileMetadata>>

Supported Input Types

TypeDescription
FileBrowser File object
BufferNode.js Buffer object
stringFile path (Node.js), data URL, or remote URL

Options

OptionTypeDescription
filenamestringCustom filename for the uploaded file
mimeTypestringOverride the file's MIME type
folderstringFolder name to upload the file into

Examples

Local file Upload

typescript
// 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"
});

Remote file Upload

typescript
// 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);
}

List Files

Retrieve a paginated list of files in your account. Requires a secret API key.

Method Signature

typescript
list(options?: { page?: number; pageSize?: number; folder?: string }): Promise<APIResponse<PaginatedResponse<FileMetadata>>>

Options

OptionTypeDescription
pagenumberPage number (default: 1)
pageSizenumberItems per page (default: 20, max: 100)
folderstringFilter files by folder name

Examples

Basic Usage

typescript
// 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
});

Get File

Retrieve metadata for a specific file by its ID. Requires a secret API key.

Method Signature

typescript
get(id: string): Promise<APIResponse<FileMetadata>>

Examples

Basic Usage

typescript
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);
}

Delete File

Permanently delete a file from your account. Requires a secret API key.

Method Signature

typescript
delete(id: string): Promise<APIResponse<void>>

Examples

Basic Usage

typescript
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);
}

Error Handling

The SDK throws errors when operations fail. Each error includes detailed information about what went wrong.

typescript
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);
  }
}

Next Steps

Continue exploring our documentation with these related topics: