Uploads a file to Pinnacle’s cloud storage. The method handles file validation, MIME type detection, and manages the complete upload process including pre-signed URL generation.
| Parameter | Type | Description |
|---|---|---|
fileInput | string | File | File path string (Node.js) or File object (browser) |
options | object (optional) | Upload configuration |
name | string | Display name (defaults to file basename or File.name) |
options | UploadFileParams.Options | Additional file options (e.g., download settings) |
Returns the download URL as a string.
| Error | Description |
|---|---|
NotFoundError | File does not exist at the specified path (Node.js only) |
BadRequestError | Path points to a directory instead of a file, or invalid file input type for the environment |
InternalServerError | File system operation failed (permissions, disk errors) |
1 import { PinnacleClient } from 'rcs-js'; 2 3 const client = new PinnacleClient({ apiKey: process.env.PINNACLE_API_KEY }); 4 5 // Upload from file path 6 async function uploadDocument() { 7 try { 8 // Returns the download URL as a string 9 const downloadUrl = await client.tools.file.uploadFromPath( 10 './media/video.mp4', 11 { 12 name: 'Product Demo Video', 13 options: { 14 download: { 15 expiresAt: '2025-12-31T23:59:59Z' 16 } 17 } 18 } 19 ); 20 21 console.log('Download URL:', downloadUrl); 22 return downloadUrl; 23 } catch (error) { 24 throw error; 25 } 26 }
1 import { PinnacleClient } from 'rcs-js'; 2 3 const client = new PinnacleClient({ apiKey: process.env.PINNACLE_API_KEY }); 4 5 // Upload from File object (e.g., from file input) 6 async function uploadFromInput(file: File) { 7 try { 8 const downloadUrl = await client.tools.file.uploadFromPath( 9 file, 10 { 11 name: 'User Upload', 12 options: { 13 download: { 14 expiresAt: '2025-12-31T23:59:59Z' 15 } 16 } 17 } 18 ); 19 20 console.log('Download URL:', downloadUrl); 21 return downloadUrl; 22 } catch (error) { 23 throw error; 24 } 25 } 26 27 // Example with file input element 28 document.getElementById('fileInput')?.addEventListener('change', async (e) => { 29 const file = (e.target as HTMLInputElement).files?.[0]; 30 if (file) { 31 await uploadFromInput(file); 32 } 33 });
