Factorial Code Storage
Factorial Code Storage is a robust file storage system designed to handle file operations within your processes. It provides a simple and efficient way to store, retrieve, and manage files through accessible source code integration.
With Factorial Code Storage, you can perform various file operations including:
- File Upload: Store files from your processes or external sources
- Automatic Form Uploads: Receive files submitted from input-parameter forms directly in storage
- File Download: Retrieve files for processing or analysis
- File Management: List and delete your stored files
- Signed URLs: Generate temporary download URLs for existing files
Use Cases
Section titled “Use Cases”Factorial Code Storage is perfect for scenarios such as:
- Document Processing: Store uploaded documents for analysis or transformation
- Image Processing: Handle image files for resizing, conversion or analysis
- Data Export: Generate and store reports, CSV files or other exports
- File Sharing: Create temporary file storage for sharing between processes
- Backup Operations: Store important files as part of backup workflows
Automatic Uploads from Input Parameter Forms
Section titled “Automatic Uploads from Input Parameter Forms”When your process uses an input parameter form with file fields ("ui:widget": "file"), Factorial Code uploads those submitted files to storage automatically before execution starts.
Inside your process code, file parameters become storage references you can use with fcode.storage.download() and other storage methods.
For one file field, you receive one storage path. If your form allows multiple files, you will receive an array of storage paths.
const { context: { parameters },} = fcode;
const uploadedPath = parameters.inputFile;// Upload path starts with "fcode.storage://"const fileStream = await fcode.storage.download(uploadedPath.replace("fcode.storage://", ""));uploaded_path = fcode.context.parameters.get("inputFile")# Upload path starts with "fcode.storage://"content = fcode.storage.download(uploaded_path.replace("fcode.storage://", ""))Access Methods
Section titled “Access Methods”Factorial Code Storage can be accessed through multiple methods, making it flexible for different use cases and integration scenarios:
1. From Process Source Code
Section titled “1. From Process Source Code”The most direct way to use Factorial Code Storage is from within your process source code using the fcode.storage helper:
const path = require("node:path");const localPath = path.join(process.env.TMP_DATA_DIR, "myfile.txt");await fcode.storage.upload("path/myfile.txt", fs.createReadStream(localPath));const files = await fcode.storage.list();console.log(files);const path = require("node:path");const localPath = path.join(process.env.TMP_DATA_DIR, "downloaded.txt");const stream = await fcode.storage.download("path/myfile.txt");stream.pipe(fs.createWriteStream(localPath));await fcode.storage.delete("path/myfile.txt");const signed = await fcode.storage.createSignedUrl("path/myfile.txt");console.log(signed.url, signed.expiresAt);
const signedWithCustomExpiry = await fcode.storage.createSignedUrl("path/myfile.txt", { expiresInSeconds: 900,});console.log(signedWithCustomExpiry.url, signedWithCustomExpiry.expiresAt);import oslocal_path = os.path.join(os.environ.get("TMP_DATA_DIR"), "myfile.txt")with open(local_path, "rb") as f: obj = fcode.storage.upload("path/myfile.txt", f) print("Uploaded:", obj.name, obj.size, obj.link)objects = fcode.storage.list()for obj in objects: print(obj.name, obj.size, obj.link)import oslocal_path = os.path.join(os.environ.get("TMP_DATA_DIR"), "downloaded.txt")content = fcode.storage.download("path/myfile.txt")with open(local_path, "wb") as f: f.write(content)fcode.storage.delete("myfile.txt")signed = fcode.storage.create_signed_url("path/myfile.txt")print(signed.url, signed.expires_at)
signed_custom = fcode.storage.create_signed_url( "path/myfile.txt", expires_in_seconds=900)print(signed_custom.url, signed_custom.expires_at)2. From External Systems via REST API
Section titled “2. From External Systems via REST API”Factorial Code Storage is also available through our REST API, allowing you to upload, download, list, delete, and create signed URLs from any external system. This enables integration with third-party applications, web services, or any system that can make HTTP requests.
3. Using Factorial Code Run SDK
Section titled “3. Using Factorial Code Run SDK”You can interact with Factorial Code Storage from external applications using our Factorial Code Run SDK, available for both JavaScript and Python:
const { FcodeStorage } = require('@factorialco/fcode-sdk');const fs = require('fs');
const storage = new FcodeStorage({ apiToken: 'your-api-token' });
// Upload a file (using Node.js stream)await storage.upload('path/myfile.txt', fs.createReadStream('./myfile.txt'));
// List filesconst files = await storage.list();console.log(files);
// Download a fileconst stream = await storage.download('path/myfile.txt');stream.pipe(fs.createWriteStream('./downloaded.txt'));
// Delete a fileawait storage.delete('myfile.txt');
// Create a temporary signed URL (default expiration ~1 hour)const signed = await storage.createSignedUrl('path/myfile.txt');console.log(signed.url, signed.expiresAt);
// Custom expirationconst signedWithCustomExpiry = await storage.createSignedUrl('path/myfile.txt', { expiresInSeconds: 900,});console.log(signedWithCustomExpiry.url, signedWithCustomExpiry.expiresAt);Install the SDK: pnpm install @factorialco/fcode-sdk
from fcode_sdk import FcodeStorage, FcodeApiConfig
storage = FcodeStorage( FcodeApiConfig(api_token='your-api-token'))
# Upload a filewith open('myfile.txt', 'rb') as f: obj = storage.upload('myfile.txt', f) print('Uploaded:', obj.name, obj.size, obj.link)
# List all storage objectsobjects = storage.list()for obj in objects: print(obj.name, obj.size, obj.link)
# Download a filecontent = storage.download('myfile.txt')with open('downloaded.txt', 'wb') as f: f.write(content)
# Delete a filestorage.delete('myfile.txt')
# Create a temporary signed URL (default expiration ~1 hour)signed = storage.create_signed_url('path/myfile.txt')print(signed.url, signed.expires_at)
# Custom expirationsigned_custom = storage.create_signed_url( 'path/myfile.txt', expires_in_seconds=900)print(signed_custom.url, signed_custom.expires_at)Install the SDK: pip install factorial-fcode-sdk
4. From AI Agents via MCP Server
Section titled “4. From AI Agents via MCP Server”Factorial Code Storage is available as MCP (Model Context Protocol) tools in our MCP server, making it incredibly powerful when combined with AI agents. This enables AI agents to:
- Handle file-based tasks end-to-end without manual intervention
- Process complex data using the full power of Python/JavaScript ecosystems
- Store and retrieve results securely in the cloud
- Chain multiple operations across different files and datasets
When combined with our run_code tool, AI agents can upload files, generate and execute code to process them, and store results back to Factorial Code Storage automatically.
Working with Local Disk
Section titled “Working with Local Disk”Factorial Code Storage works seamlessly with local disk for comprehensive file handling workflows. This combination is particularly useful when you need to:
- Process files that require specific file paths or libraries that don’t support streams
- Perform complex data transformations that benefit from local file access
- Handle large files that need to be processed in chunks