Overview
The CDN API allows you to upload and retrieve files from the Lua CDN. Files are stored securely and can be accessed by their unique file ID.Methods
upload
Uploads a file to the CDN.
Returns:
Promise<string> - The unique file ID
Example:
get
Retrieves a file from the CDN by its ID.
Returns:
Promise<File> - The File object with name, type, and size properties
Example:
Use Cases
Store User Uploads
Retrieve and Process Files
Use with AI for Image Analysis
Re-upload Files
SinceCDN.get() returns a File object, you can easily re-upload files:
File Properties
TheFile object returned by CDN.get() has these properties:
And these methods:
Supported File Types
The CDN supports all file types including:- Images: PNG, JPEG, GIF, WebP, SVG
- Documents: PDF, DOC, DOCX, TXT
- Data: JSON, CSV, XML
- Audio/Video: MP3, MP4, WAV
- Archives: ZIP, TAR
Best Practices
Use Descriptive Filenames
Use Descriptive Filenames
Include meaningful names when creating Files:
Set Correct MIME Types
Set Correct MIME Types
Always specify the correct MIME type:
Store File IDs
Store File IDs
Save file IDs in your data for later retrieval:
Handle Errors
Handle Errors
Always handle potential errors:
Complete Example
If a CDN upload or retrieval isn’t working as expected, log file metadata to inspect what was returned:Then run
lua logs --type skill --limit 5 after a test message. See the Debugging Skills guide for the full workflow.
