Social Media Scraping 2 min read

How to Download TikTok Videos and Store Them on a CDN

Learn how to programmatically download TikTok videos and store them in cloud CDNs like Supabase, S3, or Cloudinary.

by
How to Download and Store TikTok Videos Using CDNs

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];
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 = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY);

const filePath = "video.mp4";
const bucket = "videos";
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);
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.

FAQ

Frequently asked
questions

Can't find what you're looking for? Email me.

Adrian Horning

Written by

Adrian Horning

Founder of ScrapeCreators. I write about social data APIs, scraper reliability, and turning public creator data into useful products.

Connect

ScrapeCreatorsScrapeCreators

Social Media Scraping API
for Developers

Real-time data from TikTok, Instagram, YouTube, X, Facebook, Reddit, and more.

Real-time Data

Fresh, accurate, always up-to-date.

No Proxies

We handle the infrastructure.

Developer First

Simple API. Powerful results.

TikTok logoInstagram logoYouTube logoX logoFacebook logoReddit logo
{200 OK
"platform": "youtube",
"type": "video",
"title": "Never Gonna Give You Up",
"views": 12504321,
"transcript": "We're no strangers to love...",
}
Success124ms
Purple gift box representing 100 free ScrapeCreators credits

Get 100 credits on us - instantly.

No credit card required. Start building for free.

Try the API, on us.

New developers get 100 free credits automatically when they sign up. No credit card required.

Get started free
Trusted by 10,000+ developers
99.9% uptime
SOC 2 Compliant