
File Upload API
OfficialFreeIntegrate file uploads into your React UI bundle.
Free · Opens the source repo
What File Upload API does
The File Upload API skill provides a robust solution for adding file upload functionality to your React UI bundle applications. It is designed specifically for projects that include a uiBundles/*/src/ directory and require the capability to upload, attach, or drop files. By utilizing this skill, developers can streamline the process of integrating file uploads without having to build the functionality from scratch. The skill offers programmatic APIs that facilitate file uploads with progress tracking and integration with Salesforce's ContentVersion records.
This skill is particularly beneficial for developers who need to create custom user interfaces for file uploads. It does not provide pre-built components, but instead, it offers the upload() API, which developers can use to implement their own UI elements such as file inputs, dropzones, and progress indicators. The skill supports various upload patterns, allowing for flexibility depending on whether files need to be linked to existing records or uploaded independently.
With the ability to track upload progress through the onProgress callback, developers can provide users with real-time feedback on their uploads. This feature enhances the user experience by allowing for the display of upload statuses and progress percentages. Additionally, the skill supports cancellation of uploads through the use of an AbortController, giving users control over their file upload processes.
Overall, the File Upload API skill is an essential tool for developers looking to implement file upload capabilities in their Salesforce-connected applications. It provides the necessary backend functionality while allowing developers the freedom to create tailored front-end experiences that meet their specific application needs.
When to use it
Use this skill when you need to add file upload capabilities to a UI bundle app, particularly when working with Salesforce records.
When not to use it
This skill is not suitable if you require pre-built UI components or if your project does not involve Salesforce integration.
What you can build with it
Basic File Upload
Use the basic upload pattern to allow users to upload files without linking them to any existing records, suitable for multi-step forms.
Immediate Record Linking
Utilize the immediate record linking pattern to upload files and attach them directly to existing Salesforce records.
Deferred Record Linking
Implement a flow where files are uploaded first, and then linked to a newly created record after form submission.
How to install File Upload API
View source1. Install with the skills CLI
npx skills add forcedotcom/sf-skills/experience-ui-bundle-file-upload-generate --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by forcedotcomFile Upload API (workflow)
When the user wants file upload functionality in a React UI bundle, follow this workflow. This feature provides APIs only — you must build the UI components yourself using the provided APIs.
CRITICAL: This is an API-only package
The package exports programmatic APIs, not React components or hooks. You will:
- Use the
upload()function to handle file uploads with progress tracking - Build your own custom UI (file input, dropzone, progress bars, etc.)
- Track upload progress through the
onProgresscallback
Do NOT:
- Expect pre-built components like
<FileUpload />— they are not exported - Try to import React hooks like
useFileUpload— they are not exported - Look for dropzone components — they are not exported
The source code contains reference components for demonstration, but they are not available as imports. Use them as examples to build your own UI.
1. Install the package
npm install @salesforce/ui-bundle-template-feature-react-file-upload
Dependencies are automatically installed:
@salesforce/ui-bundle(API client)@salesforce/platform-sdk(data SDK; the old@salesforce/sdk-dataname is dead — see theexperience-ui-bundle-salesforce-data-accessskill)
2. Understand the three upload patterns
Pattern A: Basic upload (no record linking)
Upload files to Salesforce and get back contentBodyId for each file. No ContentVersion record is created.
When to use:
- User wants to upload files first, then create/link them to a record later
- Building a multi-step form where the record doesn't exist yet
- Deferred record linking scenarios
import { upload } from "@salesforce/ui-bundle-template-feature-react-file-upload";
const results = await upload({
files: [file1, file2],
onProgress: (progress) => {
console.log(`${progress.fileName}: ${progress.status} - ${progress.progress}%`);
},
});
// results[0].contentBodyId: "069..." (always available)
// results[0].contentVersionId: undefined (no record linked)
Pattern B: Upload with immediate record linking
Upload files and immediately link them to an existing Salesforce record by creating ContentVersion records.
When to use:
- Record already exists (Account, Opportunity, Case, etc.)
- User wants files immediately attached to the record
- Direct upload-and-attach scenarios
import { upload } from "@salesforce/ui-bundle-template-feature-react-file-upload";
const results = await upload({
files: [file1, file2],
recordId: "001xx000000yyyy", // Existing record ID
onProgress: (progress) => {
console.log(`${progress.fileName}: ${progress.status} - ${progress.progress}%`);
},
});
// results[0].contentBodyId: "069..." (always available)
// results[0].contentVersionId: "068..." (linked to record)
Pattern C: Deferred record linking (record creation flow)
Upload files without a record, then link them after the record is created.
When to use:
- Building a "create record with attachments" form
- Record doesn't exist until form submission
- Need to upload files before knowing the final record ID
import {
upload,
createContentVersion,
} from "@salesforce/ui-bundle-template-feature-react-file-upload";
// Step 1: Upload files (no recordId)
const uploadResults = await upload({
files: [file1, file2],
onProgress: (progress) => console.log(progress),
});
// Step 2: Create the record
const newRecordId = await createRecord(formData);
// Step 3: Link uploaded files to the new record
for (const file of uploadResults) {
const contentVersionId = await createContentVersion(
new File([""], file.fileName),
file.contentBodyId,
newRecordId,
);
}
3. Build your custom UI
The package provides the backend — you build the frontend. Here's a minimal example:
import {
upload,
type FileUploadProgress,
} from "@salesforce/ui-bundle-template-feature-react-file-upload";
import { useState } from "react";
function CustomFileUpload({ recordId }: { recordId?: string }) {
const [progress, setProgress] = useState<Map<string, FileUploadProgress>>(new Map());
const handleFileSelect = async (event: React.ChangeEvent<HTMLInputElement>) => {
const files = Array.from(event.target.files || []);
await upload({
files,
recordId,
onProgress: (fileProgress) => {
setProgress((prev) => new Map(prev).set(fileProgress.fileName, fileProgress));
},
});
};
return (
<div>
<input type="file" multiple onChange={handleFileSelect} />
{Array.from(progress.entries()).map(([fileName, fileProgress]) => (
<div key={fileName}>
{fileName}: {fileProgress.status} - {fileProgress.progress}%
{fileProgress.error && <span>Error: {fileProgress.error}</span>}
</div>
))}
</div>
);
}
4. Track upload progress
The onProgress callback fires multiple times for each file as it moves through stages:
| Status | When | Progress Value |
|---|---|---|
"pending" | File queued for upload | 0 |
"uploading" | Upload in progress (XHR) | 0-100 (percentage) |
"processing" | Creating ContentVersion (if recordId provided) | 0 |
"success" | Upload complete | 100 |
"error" | Upload failed | 0 |
Always provide visual feedback:
- Show file name
- Display current status
- Render progress bar for "uploading" status
- Show error message if status is "error"
5. Cancel uploads (optional)
Use an AbortController to allow users to cancel uploads:
const abortController = new AbortController();
const handleUpload = async (files: File[]) => {
try {
await upload({
files,
signal: abortController.signal,
onProgress: (progress) => console.log(progress),
});
} catch (error) {
console.error("Upload cancelled or failed:", error);
}
};
const cancelUpload = () => {
abortController.abort();
};
6. Link to current user (special case)
If the user wants to upload files to their own profile or personal library:
import {
upload,
getCurrentUserId,
} from "@salesforce/ui-bundle-template-feature-react-file-upload";
const userId = await getCurrentUserId();
await upload({ files, recordId: userId });
API Reference
upload(options)
Main upload API that handles complete flow with progress tracking.
interface UploadOptions {
files: File[];
recordId?: string | null; // If provided, creates ContentVersion
onProgress?: (progress: FileUploadProgress) => void;
signal?: AbortSignal; // Optional cancellation
}
interface FileUploadProgress {
fileName: string;
status: "pending" | "uploading" | "processing" | "success" | "error";
progress: number; // 0-100 for uploading, 0 for other states
error?: string;
}
interface FileUploadResult {
fileName: string;
size: number;
contentBodyId: string; // Always available
contentVersionId?: string; // Only if recordId was provided
}
Returns: Promise<FileUploadResult[]>
createContentVersion(file, contentBodyId, recordId)
Manually create a ContentVersion record from a previously uploaded file.
async function createContentVersion(
file: File,
contentBodyId: string,
recordId: string,
): Promise<string | undefined>;
Parameters:
file— File object (used for metadata like name)contentBodyId— ContentBody ID from previous uploadrecordId— Record ID for FirstPublishLocationId
Returns: ContentVersion ID if successful
getCurrentUserId()
Get the current user's Salesforce ID.
async function getCurrentUserId(): Promise<string>;
Returns: Current user ID
Common UI patterns
File input with button
<input type="file" multiple accept=".pdf,.doc,.docx,.jpg,.png" onChange={handleFileSelect} />
Drag-and-drop zone
Build your own dropzone using native events:
function DropZone({ onDrop }: { onDrop: (files: File[]) => void }) {
const handleDrop = (e: React.DragEvent) => {
e.preventDefault();
const files = Array.from(e.dataTransfer.files);
onDrop(files);
};
return (
<div
onDrop={handleDrop}
onDragOver={(e) => e.preventDefault()}
style={{ border: "2px dashed #ccc", padding: "2rem" }}
>
Drop files here
</div>
);
}
Progress bar
{
progress.status === "uploading" && (
<div style={{ width: "100%", background: "#eee" }}>
<div
style={{
width: `${progress.progress}%`,
background: "#0176d3",
height: "8px",
}}
/>
</div>
);
}
Decision tree for agents
User asks for file upload functionality:
-
Ask about record context:
- "Do you want to link uploaded files to a specific record, or upload them first and link later?"
-
Based on response:
- Link to existing record → Use Pattern B with
recordId - Upload first, link later → Use Pattern A (no recordId), then Pattern C for linking
- Link to current user → Use Pattern B with
getCurrentUserId()
- Link to existing record → Use Pattern B with
-
Build the UI:
- Create file input or dropzone (not provided by package)
- Add progress display for each file (status + progress bar)
- Handle errors in the UI
-
Test the implementation:
- Verify progress callbacks fire correctly
- Check that
contentBodyIdis returned - If
recordIdwas provided, verifycontentVersionIdis returned
Reference implementation
The package includes a reference implementation in src/features/fileupload/ with:
FileUpload.tsx— Complete component with dropzone and dialogFileUploadDialog.tsx— Progress tracking dialogFileUploadDropZone.tsx— Drag-and-drop zoneuseFileUpload.ts— React hook for state management
These are NOT exported but can be viewed as examples. Read the source files to understand patterns for building your own UI.
Troubleshooting
Upload fails with CORS error:
- Ensure the UI bundle is properly deployed to Salesforce or running on
localhost - Check that the org allows the origin in CORS settings
No progress updates:
- Verify
onProgresscallback is provided - Check that the callback function updates React state correctly
ContentVersion not created:
- Verify
recordIdis provided toupload()function - Check that the record ID is valid and exists in the org
- Ensure user has permissions to create ContentVersion records
Files upload but don't appear in record:
- Verify
recordIdis correct - Check that ContentVersion was created (look for
contentVersionIdin results) - Confirm user has access to view files on the record
DO NOT do these things
- ❌ Build XHR/fetch upload logic from scratch — use the
upload()API - ❌ Try to import
<FileUpload />component — it's not exported - ❌ Try to import
useFileUploadhook — it's not exported - ❌ Use third-party file upload libraries when this feature exists
- ❌ Skip progress tracking — always provide user feedback
- ❌ Ignore errors — always handle and display error messages
Frequently asked questions about File Upload API
Similar skills
WinMD API Search
Easily find and explore Windows desktop APIs.
WebMCPify
Transform any web app into an agent-ready platform.
Phoenix Tracing
Instrument LLM applications with OpenInference tracing.
Foundry Hosted Agent CopilotKit
Guidance for developing agentic web apps on Azure.
Power Automate Foundation
Connect AI agents to Power Automate seamlessly.
Power Automate Flow Builder
Efficiently build and deploy Power Automate flows programmatically.
