Overview
MythIQ provides a robust file storage system for handling media files generated by AI models or uploaded by users. This system ensures that files are securely stored, easily accessible, and properly managed throughout their lifecycle.
The file storage system is designed to:
- Securely store generated images, videos, and other media
- Support user uploads for use with AI models
- Provide fast and reliable access to stored files
- Manage file retention according to configurable policies
- Optimize storage costs while maintaining performance
Secure and Scalable
Our file storage system is designed for security, performance, and scalability, ensuring your media files are always available when you need them.
Storage Architecture
MythIQ uses a multi-tiered storage architecture to balance performance, cost, and reliability:
Object Storage
The primary storage layer is a distributed object storage system (based on S3-compatible technology) that provides high durability and availability for all media files. Files are organized in a hierarchical structure based on user ID and file ID.
Content Delivery Network (CDN)
A global CDN sits in front of the object storage to provide low-latency access to files from anywhere in the world. The CDN caches frequently accessed files at edge locations to minimize load times and reduce bandwidth costs.
Database Metadata
File metadata (such as creation time, size, MIME type, and associated model/provider information) is stored in a relational database for efficient querying and management. This separation of concerns allows for fast searches and listings without having to scan the object storage.
File Lifecycle
Files in MythIQ go through several stages during their lifecycle:
Creation
Files are created either through AI generation (via API calls to models) or through direct uploads from users. In both cases, the file is assigned a unique ID and stored in the object storage system.
Generated Files
When a file is generated by an AI model, it is automatically stored in the object storage system and associated with the user who made the request. The file's metadata includes information about the model and provider used for generation.
Uploaded Files
For user uploads, MythIQ provides a two-step process:
- Request a presigned upload URL from the API
- Upload the file directly to the object storage using the presigned URL
- Confirm the upload to update metadata and make the file available
Access
Files can be accessed through their URLs, which are returned in API responses. These URLs point to the CDN, which serves the files with low latency. Access control is enforced based on file visibility settings and user permissions.
Public vs. Private Files
Files can be marked as public or private:
- Public files are accessible to anyone with the URL
- Private files require authentication and are only accessible to the owner
Retention and Deletion
Files are retained according to configurable policies. By default, files are stored for 30 days, but this period can be extended based on account settings or specific requirements.
Automatic Deletion
Files that exceed their retention period are automatically marked for deletion. The actual deletion process runs periodically to remove files from both the object storage and the metadata database.
Manual Deletion
Users can manually delete files at any time through the API. This immediately marks the file for deletion and removes it from search results and listings.
File Upload Process
MythIQ provides a secure and efficient process for uploading files:
Step 1: Request Upload URL
First, request a presigned upload URL from the API:
// Request a presigned upload URL
const response = await fetch('https://api.mythiq.ai/v1/media/upload', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY',
},
body: JSON.stringify({
name: 'example.jpg',
mime: 'image/jpeg',
}),
});
const { result } = await response.json();
const { url, id } = result;
Step 2: Upload File
Next, upload the file directly to the presigned URL:
// Upload the file to the presigned URL
const fileData = /* your file data as a Buffer or Blob */;
await fetch(url, {
method: 'PUT',
body: fileData,
headers: {
'Content-Type': 'image/jpeg',
},
});
Step 3: Complete Upload
Finally, confirm the upload to update metadata and make the file available:
// Complete the upload process
const completeResponse = await fetch(`https://api.mythiq.ai/v1/media/${id}`, {
method: 'PUT',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
},
});
const completeData = await completeResponse.json();
console.log(completeData.result); // Contains file metadata and URL
File Access and Management
Listing Files
You can list your files using the media endpoint:
// List your files
const response = await fetch('https://api.mythiq.ai/v1/media?user=me&limit=10', {
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
},
});
const data = await response.json();
console.log(data.result.medias); // Array of file objects
Filtering and Searching
The media endpoint supports various filtering and search parameters:
media
: Filter by media type (e.g., 'image', 'video')model
: Filter by model ID or 'base/slug' formatprovider
: Filter by provider ID or slugsearch
: Search in prompt textsort
: Sort order ('newest' or 'oldest')
File Metadata
Each file object includes comprehensive metadata:
{
"id": "abc123",
"url": "https://cdn.example.com/user/abc123/main.jpg",
"mime": "image/jpeg",
"user": "user123",
"media": "image",
"model": "stability/sdxl",
"provider": "stability",
"prompt": "A beautiful sunset over the ocean",
"size": "1024x1024",
"createdAt": "2025-03-25T12:00:00Z",
"modelSlug": "stability/sdxl:1.0",
"providerName": "Stability AI"
}
Best Practices
Efficient File Management
To optimize your use of the file storage system:
- Download and store locally any files you need to keep beyond the retention period
- Use appropriate file formats and sizes to minimize storage costs
- Clean up unused files by deleting them when they're no longer needed
Security Considerations
To maintain the security of your files:
- Set appropriate visibility (public/private) based on the sensitivity of the content
- Regularly rotate API keys to minimize the risk of unauthorized access
- Validate file types and sizes before uploading to prevent security issues
Performance Optimization
To ensure optimal performance when working with files:
- Use the CDN URLs provided in API responses for fastest access
- Implement client-side caching for frequently accessed files
- Consider image and video optimization techniques for your application