Storing TikTok videos for analysis, content management, or archival purposes requires a systematic approach to downloading and cloud storage.
This tutorial walks through the complete process of extracting TikTok video URLs, downloading the files, and storing them in a CDN for reliable access.
Understanding TikTok Video URLs
TikTok videos are served through direct URLs that provide access to the raw MP4 files.
These URLs are embedded in TikTok's API responses and can be extracted programmatically. However, TikTok's video URLs are temporary and designed to prevent direct linking, so immediate processing is essential.
When you scrape a TikTok video using an API service, the response typically includes a direct link to the video file hosted on TikTok's content delivery network. These URLs look something like:
https://v16-webapp.tiktok.com/video/tos/...[long hash]/video.mp4
Step 1: Extracting Video URLs
Using the Scrape Creators API, you can easily extract the direct video URL from any TikTok post:
The API response provides the direct video URL that you can use to download the actual video file.
Step 2: Downloading the Video File
Once you have the direct video URL, download it to your server using a reliable HTTP client.
The Impit library from Apify works well for this purpose, especially when dealing with potential 403 errors that might require proxy usage.
const res = await axios.get(
"https://api.scrapecreators.com/v2/tiktok/video?url=https://www.tiktok.com/@stoolpresidente/video/7552934044887944478",
{
headers: {
"x-api-key": process.env.MY_API_KEY,
},
}
);
const rawVideo = res?.data?.aweme_detail?.video?.play_addr?.url_list?.[0];
console.log("rawVideo", rawVideo);
const videoRes = await impit.fetch(rawVideo);
const buffer = Buffer.from(await videoRes.arrayBuffer());
fs.writeFileSync("video.mp4", buffer);
Proxy Considerations
TikTok may return 403 Forbidden errors for automated requests. Using proxies helps avoid these blocks:
Recommended Proxy Providers:
- Evomi: Reliable residential proxies with good TikTok success rates
- Webshare: Cost-effective datacenter proxies for moderate usage
- Decodo: Premium service with high reliability for production applications
Step 3: Uploading to Cloud Storage
After downloading the video locally, upload it to your chosen CDN. This example uses Supabase, but the pattern works for AWS S3, Cloudinary, or other storage services.
Supabase Upload Implementation
import fs from 'fs';
import { createClient } from '@supabase/supabase-js';
const SUPABASE_URL = process.env.SUPABASE_URL;
const SUPABASE_KEY = process.env.SUPABASE_KEY;
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY);
const filePath = 'video.mp4';
const bucket = 'videos'; // change to your bucket
const storagePath = `uploads/${filePath}`;
const fileBuffer = fs.readFileSync(filePath);
const { error } = await supabase.storage
.from(bucket)
.upload(storagePath, fileBuffer, {
contentType: 'video/mp4',
upsert: true
});
if (error) throw error;
fs.unlinkSync(filePath); // delete local file
console.log('Uploaded and deleted local copy.');
Conclusion
This workflow provides a robust foundation for downloading and storing TikTok videos at scale while handling errors gracefully and maintaining good performance practices.