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.| Parameter | Type | Description |
|---|---|---|
file | File | The File object to upload |
Promise<string> - The unique file ID
Example:
get
Retrieves a file from the CDN by its ID.| Parameter | Type | Description |
|---|---|---|
fileId | string | The unique identifier of the file |
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:
| Property | Type | Description |
|---|---|---|
name | string | Original filename |
type | string | MIME type (e.g., image/png) |
size | number | File size in bytes |
| Method | Returns | Description |
|---|---|---|
text() | Promise<string> | Read as text |
arrayBuffer() | Promise<ArrayBuffer> | Read as binary |
stream() | ReadableStream | Read as stream |
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:

