Supported file types
Request parameters that accept file uploads support multiple formats:File API
Web-standard
File objects or compatible structuresReadStream
Node.js
fs.ReadStream for file system accessResponse
fetch Response objects or compatible structurestoFile Helper
SDK’s
toFile() helper for buffers and arraysFile upload methods
- ReadStream (Node.js)
- File API (Browser)
- Fetch Response
- toFile Helper
Use
fs.createReadStream() for optimal performance in Node.js:This is the recommended approach for Node.js environments as it streams the file without loading it entirely into memory.
The toFile helper
ThetoFile() helper converts raw data into an uploadable format:
Usage examples
Buffer | Uint8Array | ArrayBuffer
required
Raw binary data to upload
string
required
Name for the uploaded file
string
MIME type of the file (e.g.,
"application/json")Reading files from disk
UsefileFromPath() to read files from the filesystem:
fileFromPath() is only available in Node.js environments.Complete upload examples
API Gateway schema upload
Dynamic file generation
Remote file upload
Multipart form data
File uploads use multipart/form-data encoding automatically:The SDK automatically sets the correct
Content-Type: multipart/form-data header and constructs the multipart body.File metadata
When using theFile API or toFile(), you can specify metadata:
Best practices
1
Use streams for large files
In Node.js, prefer
fs.createReadStream() to avoid loading entire files into memory:2
Set correct MIME types
Specify the correct content type for better compatibility:
3
Handle file errors
Wrap file operations in try-catch blocks:
4
Validate files before upload
Check file size and format before initiating uploads: