Skip to content

Add file upload example script#5

Open
raytiley wants to merge 1 commit intomainfrom
file-upload-example
Open

Add file upload example script#5
raytiley wants to merge 1 commit intomainfrom
file-upload-example

Conversation

@raytiley
Copy link
Member

@raytiley raytiley commented Mar 6, 2026

Summary

  • Adds js/file-upload.mjs demonstrating the full chunked FileUpload API workflow
  • Creates upload job, uploads segments, marks complete, polls until server finishes processing
  • Tested end-to-end against eng-demo (uploaded file, got asset ID back)
  • Updates README with usage docs for the new script

Related

Test plan

  • Run node file-upload.mjs <path-to-file> 11 against eng-demo
  • Verify upload completes and asset is created
  • Try with files larger than 5MB to exercise chunking

🤖 Generated with Claude Code

@raytiley raytiley requested a review from Copilot March 19, 2026 13:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new JavaScript example script demonstrating the chunked FileUpload workflow against the Cablecast API, and documents how to run it from the repository README.

Changes:

  • Add js/file-upload.mjs example that creates an upload job, uploads segments via multipart, completes the upload, and polls for processing state.
  • Document the new script, expected workflow steps, and usage in README.md.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
README.md Adds usage/docs for the new file upload example script and its API workflow.
js/file-upload.mjs New end-to-end chunked upload example covering job creation, segment upload, completion, and status polling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +33 to +36
const SERVER_BASE_URL = 'https://eng-demo.cablecast.tv';
const USERNAME = 'admin';
const PASSWORD = process.env.CABLECAST_PASSWORD ?? 'yourpassword';

Comment on lines +38 to +40
const filePath = process.argv[2];
const destinationStoreId = parseInt(process.argv[3] || '11', 10);

Comment on lines +48 to +51
const fileName = basename(filePath);
const fileBuffer = readFileSync(filePath);
const fileSize = statSync(filePath).size;
const totalSegments = Math.ceil(fileSize / CHUNK_SIZE);
{
method: 'POST',
headers: {
'Authorization': `Basic ${btoa(`${USERNAME}:${PASSWORD}`)}`,
README.md Outdated
Comment on lines +22 to +29
1. Create an upload job (`POST /v1/fileuploads`)
2. Upload the file in 5 MB segments (`POST /v1/fileuploads/{id}/upload`)
3. Mark the upload complete (`PUT /v1/fileuploads/{id}`) — this creates an Asset and links it to the destination file store
4. Poll until the server finishes processing the file

Usage: `node file-upload.mjs <path-to-file> [destination-store-id]`

The destination store ID defaults to `11`. Use `GET /v1/filestores` to list available stores on your system.
Comment on lines +113 to +116
console.log('Waiting for server to process file...');
const maxWaitMs = 5 * 60 * 1000; // 5 minutes
const pollIntervalMs = 3000;
const startTime = Date.now();
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@raytiley raytiley force-pushed the file-upload-example branch from 09a8ecf to b82da63 Compare March 19, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants