Upload from Path

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.

Parameters

ParameterTypeDescription
fileInputstring | FileFile path string (Node.js) or File object (browser)
optionsobject (optional)Upload configuration
  namestringDisplay name (defaults to file basename or File.name)
  optionsUploadFileParams.OptionsAdditional file options (e.g., download settings)

Returns

Returns the download URL as a string.

Errors

ErrorDescription
NotFoundErrorFile does not exist at the specified path (Node.js only)
BadRequestErrorPath points to a directory instead of a file, or invalid file input type for the environment
InternalServerErrorFile system operation failed (permissions, disk errors)

Example Implementation

Node.js

1import { PinnacleClient } from 'rcs-js';
2
3const client = new PinnacleClient({ apiKey: process.env.PINNACLE_API_KEY });
4
5// Upload from file path
6async 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}

Browser

1import { PinnacleClient } from 'rcs-js';
2
3const client = new PinnacleClient({ apiKey: process.env.PINNACLE_API_KEY });
4
5// Upload from File object (e.g., from file input)
6async 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
28document.getElementById('fileInput')?.addEventListener('change', async (e) => {
29 const file = (e.target as HTMLInputElement).files?.[0];
30 if (file) {
31 await uploadFromInput(file);
32 }
33});