Optimizing Social Media Media Handling with Tigris Object Storage
These articles are AI-generated summaries. Please check the original sources for full details.
File uploads for a social media app with Tigris
Tigris is an S3-compatible object storage service that provides automatic global data replication and zero egress fees. The platform allows developers to push files directly from the browser to storage, bypassing the backend to save bandwidth and reduce latency.
Why This Matters
Social media backends often struggle with the bandwidth and latency overhead of routing heavy media files through application servers. While traditional S3 providers charge significant egress fees for repeated content delivery, Tigris’s zero-egress model and multi-region replication address the technical reality of high-traffic media platforms where followers frequently reload global content from worldwide locations.
Key Insights
- Tigris charges zero egress fees for data transfer, providing a major cost advantage for social platforms where media is consumed repeatedly by many users.
- The SDK follows a consistent { data, error } return pattern for all functions, simplifying error handling by eliminating the need for try-catch blocks in both server and client environments.
- Global distribution is handled automatically by Tigris without requiring a primary region selection, allowing users in Tokyo or Berlin to access files from nearby caches.
- Large files like 500 MB videos are supported via the multipart: true flag, which enables parallel chunked uploads and progress tracking through an onUploadProgress callback.
- Client-side uploads utilize the @tigrisdata/storage/client module to skip application servers entirely by generating presigned URLs for secure, direct-to-storage transfers.
Working Examples
Server-side upload for profile pictures with explicit content type and public access.
import { put } from "@tigrisdata/storage";
async function uploadAvatar(userId: string, imageBuffer: Buffer) {
const result = await put(`avatars/${userId}.jpg", imageBuffer, {
contentType: "image/jpeg",
access: "public",
allowOverwrite: true,
});
if (result.error) {
throw result.error;
}
return result.data?.url;
}
Multipart upload for large video files with progress tracking.
import { put } from "@tigrisdata/storage";
async function uploadVideo(file: ReadableStream) {
const result = await put("videos/new-post.mp4", file, {
multipart: true,
contentType: "video/mp4",
access: "private",
onUploadProgress: ({ loaded, total, percentage }) => {
console.log(`${percentage}% uploaded`);
},
});
if (result.error) {
throw result.error;
}
return result.data;
}
Browser-side direct upload utilizing a server-side presigned URL endpoint.
import { upload } from "@tigrisdata/storage/client";
async function handleUpload(event) {
const file = event.target.files[0];
const result = await upload(`posts/${file.name}`, file, {
url: "/api/upload",
multipart: true,
contentType: file.type,
onUploadProgress: ({ percentage }) => {
updateProgressBar(percentage);
},
});
if (result.error) {
console.error(result.error);
return;
}
console.log("Uploaded:", result.data.url);
}
Practical Applications
- Use Case: Validating profile pictures on the server before storage to ensure specific image dimensions or formats. Pitfall: Omitting the contentType property may lead to incorrect format inference if the file extension is missing.
- Use Case: Handling high-volume video uploads by routing data directly from the client to Tigris. Pitfall: Routing large files through application servers instead of using presigned URLs leads to high bandwidth costs and increased latency.
- Use Case: Deleting associated media when a user removes a post using the list and remove methods with prefix filtering. Pitfall: Failing to paginate the list response with paginationToken when a prefix contains more than 100 objects.
References:
Continue reading
Next article
Building Dependency-Free Health APIs: A Client-Side Architecture Case Study
Related Content
Mastering Shielded Token Lifecycles with Midnight's Compact Language
Implement private value movement in Midnight apps by building a shielded token lifecycle with mint, transfer, and burn operations using Compact.
Optimizing OpenClaw: Strategies to Reduce Token Usage by 40%
Learn how the orchestrator pattern and modular file separation can reduce OpenClaw token consumption by 40% while improving agent reliability.
Optimizing Laravel Performance: Reducing Image Bloat with Intervention Image 3
Learn how to reduce Laravel image upload sizes by 99% using Intervention Image 3 to convert 5MB JPEGs into 40KB WebP files.