Chrysolites Tech Academy

Short-Video App with React Native and Supabase · Course book

Chapter 8: The Camera and Uploads

Pairs with Lesson 8: Recording and Uploading Video

A short-video app lives or dies by how easy it is to create a clip. The camera must open quickly, the record button must respond instantly, and the finished video must reach the server reliably, even on a mobile connection. This chapter explains how recording and uploading work in an Expo app backed by Supabase Storage: asking for camera and microphone permission, showing the camera preview, recording and stopping, turning the recorded file into something that can be uploaded, organising files in a storage bucket by user, recording each upload in the database, and presenting the camera as a modal. It also works out file sizes and upload times by hand, because they shape the whole experience.

Permissions first

Phones protect the camera and microphone with permissions that the user must grant. Expo's camera library provides hooks that report the current status and request access, and recording video with sound needs both the camera and the microphone. The app should ask at the moment the user opens the camera, not at launch, so the request makes sense in context, and it must handle every answer gracefully.

StatusWhat it meansWhat the app should show
Not yet askedThe user has never been askedA short explanation and a button that triggers the system prompt
GrantedAccess allowedThe camera preview and controls
Denied, can ask againThe user said no, but the system will ask againThe explanation again, with the button
Denied permanentlyThe system will not show the prompt againA message with a button that opens the phone's settings for the app

On iOS, each permission needs a usage description, a sentence shown in the system prompt explaining why the app needs access, such as "Record videos to share with your friends". These are set in app.json through the camera library's configuration plugin. Apps are rejected from the App Store when these descriptions are missing or vague, so they are worth writing carefully.

The camera screen and recording

The camera screen is a full-screen CameraView with controls drawn on top: a large round record button at the bottom centre, a button to flip between the front and back cameras, a button to close the camera and, in the next chapter, a button to pick a video from the gallery. A reference to the camera component, created with useRef, lets the code call its methods.

const cameraRef = useRef(null);
const [isRecording, setIsRecording] = useState(false);

async function toggleRecording() {
  if (isRecording) {
    cameraRef.current?.stopRecording();
    return;
  }
  setIsRecording(true);
  try {
    const video = await cameraRef.current?.recordAsync({ maxDuration: 60 });
    if (video?.uri) await uploadVideo(video.uri);
  } finally {
    setIsRecording(false);
  }
}

The camera must be in video mode to record. recordAsync starts recording and returns a promise that resolves when recording stops, either because stopRecording was called or because the maxDuration limit was reached, giving an object with the file's local uri. Showing a red ring or a timer while recording, and disabling the flip button during recording, gives clear feedback. A maximum duration protects storage and keeps uploads manageable. The flash or torch, a zoom gesture and a countdown before recording starts are natural extras once the basics work, each controlled by a property on the camera component and a small piece of state.

How big is a clip, and how long does it take to upload?

A video's size is roughly its bitrate multiplied by its length, and phone cameras record at high bitrates by default. Upload time is the size divided by the upload speed, and upload speeds on mobile networks are usually much lower than download speeds.

Worked example. A 30-second clip at 6 megabits per second is 30 × 6 = 180 megabits, or 180 / 8 = 22.5 megabytes. On a connection that uploads at 5 megabits per second, it takes 180 / 5 = 36 seconds to upload. On a weak 2 megabit connection it takes 90 seconds, and on a fast 20 megabit connection only 9 seconds. Halving the bitrate, for example by recording at a lower resolution, halves both the size and the wait.
2 Mbit/s: 180 s 5 Mbit/s: 72 s 20 Mbit/s: 18 s 060120180 015304560 clip length (seconds), recorded at 6 Mbit/supload time (s)
Figure 8.1 — Upload time grows with clip length and falls with connection speed. On slow networks, long clips at high bitrates keep users waiting for minutes.

These numbers argue for three design choices: a sensible maximum duration, a moderate recording quality setting, and an upload that shows progress and does not block the rest of the app, so the user can keep browsing while the clip uploads.

Mobile connections drop, especially when someone walks out of range of a network. For large files, a resumable upload splits the file into chunks, sends them one at a time and, if the connection fails, continues from the last chunk that arrived rather than starting again. Supabase Storage supports a resumable upload protocol for this purpose, which is worth adopting once clips regularly exceed a few megabytes. Another option is to compress the video on the phone before uploading, re-encoding it at a lower bitrate; this costs a few seconds of processing and some battery, but on slow networks it can save far more time than it takes. Whatever the method, keep the recorded file on the phone until the upload has succeeded, so nothing is lost if it fails.

Short-video apps are built around vertical video in a 9:16 aspect ratio, which fills a phone held upright. A 1080 × 1920 frame has a ratio of 1080 / 1920 = 0.5625, exactly 9 / 16. Recording in portrait, and locking the camera screen to portrait orientation, keeps every clip consistent with the feed, so videos fill the screen without black bars.

Uploading to Supabase Storage

Supabase Storage keeps files in buckets, each with its own access rules. A videos bucket holds the clips. Organising files by user, with a path such as {userId}/{timestamp}.mp4, keeps each user's files together and makes security rules simple: a storage policy can allow uploads only when the first folder of the path equals the uploader's id, using auth.uid(). A timestamp, or a random UUID, makes each file name unique so uploads never overwrite each other.

In React Native, the recorded video is a local file identified by its uri. Uploading it means reading the file's bytes and sending them with the right content type. A dependable approach is to read the file into an ArrayBuffer, or to build a FormData object containing the file, and pass it to supabase.storage.from("videos").upload(path, data, { contentType: "video/mp4" }). The call returns the stored path or an error, which the app must check.

Once the file is stored, the app inserts a row into the Video table with the path, the user's id and a title. Storing the path rather than a full web address matters: if the bucket is private, the app creates a time-limited signed address when it plays the video, and paths stay valid even if the project's address changes. If the database insert fails after a successful upload, the file is left without a row; for a robust app, retry the insert, or delete the orphaned file, so storage does not fill with clips nobody can see.

A modal camera and a smooth flow

Recording is a focused task, so the camera usually opens as a modal: a full-screen layer that slides up over the tabs and hides the tab bar, with a close button to return. In Expo Router, a screen can be presented as a modal by setting its presentation option in the layout, and the camera tab can open it instead of switching to a normal tab.

After a recording finishes, a smooth flow closes the camera, shows that the upload is in progress, and returns the user to the feed or their profile, where the new video appears once its database row exists. Using TanStack Query, the app invalidates the queries for the feed and the profile after a successful upload, so they refetch automatically. Testing on a real device is essential here: simulators often lack a camera, and real upload speeds, permissions and file formats only show up on actual phones.

Two final details prevent common bugs. Turn the camera off when its screen is not visible, by rendering it only while the screen is focused, so it does not drain the battery or keep the camera light on. And release recording state in a finally block, as in the code above, so a failed upload never leaves the button stuck in its recording state. Show a clear message when an upload fails, with a button to try again.

Practice tasks

  1. Compute the size of a 45-second clip recorded at 8 megabits per second, and its upload time at 4 megabits per second.
  2. How long would a 60-second, 6 megabit clip take to upload at 10 megabits per second?
  3. Write the storage path for a clip uploaded by user abc123 at timestamp 1700000000000, and the policy check that allows it.
  4. Explain why the database stores the file's path rather than a full address.
  5. Describe what the camera screen should show when permission has been denied permanently.
  6. Why should the recording state be reset in a finally block?

Install Chrysolites Tech Academy

Android / Chrome / Edge: open the browser menu and choose Install app or Add to Home screen.

iPhone / iPad (Safari): tap the Share button, then Add to Home Screen.