Skip to main content

Media Upload And Storage Module

Quick Answer

The media module lives in src/core/media. It normalizes local files, validates image and video size, processes images, generates video metadata, and routes uploads to the active storage provider.

Most media bugs are not camera bugs. They usually happen after the user selects a file, during validation, upload, Firebase Function execution, Storage permissions, or Firestore writes that reference the uploaded URL.

Source Map

src/core/media
|-- mediaProcessor.js
|-- ExpoAVCompatibility.js
|-- api
| |-- firebase/storage.js
| |-- aws/storage.js
| |-- backend/storage.js
| `-- local/storage.js
`-- index.js

Important responsibilities:

FilePurpose
mediaProcessor.jsNormalizes file objects, validates size/duration, compresses images, and prepares upload metadata.
api/firebase/storage.jsFirebase-backed media upload implementation.
api/aws/storage.jsAWS-backed media upload implementation.
api/backend/storage.jsCustom backend upload implementation.
api/local/storage.jsLocal/demo upload implementation.
index.jsSelects the active storage provider.

Active Storage Provider

The active provider is selected in:

src/core/media/index.js

Firebase apps usually export:

import storageAPI from './api/firebase/storage'
export { storageAPI }

If you move to AWS or your own backend, switch the export and keep the public API shape compatible with the callers.

Media Validation

The module validates:

  • missing file URI;
  • image file size;
  • video file size;
  • video duration;
  • MIME type inference;
  • fallback file names.

Common limits are defined in mediaProcessor.js. If you raise limits, check upload costs, mobile bandwidth, backend timeout, and store review implications before release.

Firebase Upload Requirements

For Firebase-backed uploads, verify:

  • Firebase Storage is enabled.
  • Firebase Functions are deployed if uploads go through an upload Function.
  • The app uses your Firebase project, not demo config.
  • Storage rules allow authenticated users to upload only allowed paths.
  • Firestore rules allow writing the final post/listing/profile/chat document.
  • Blaze billing is enabled when Functions or large media workflows require it.

Where Media Is Used

Media is commonly used by:

  • social feed posts and stories;
  • chat media messages;
  • profile photos;
  • listing photos;
  • vendor photos;
  • reviews with images;
  • video-style apps.

The calling feature should show the user whether the failure happened during media validation, media upload, or final database write.

Verification Checklist

Test:

  • image selected from gallery;
  • image captured from camera;
  • video selected or recorded if the app supports video;
  • too-large image is rejected gracefully;
  • too-large video is rejected gracefully;
  • upload succeeds on Wi-Fi and mobile data;
  • upload failure shows a useful message;
  • final URL appears in the post/listing/profile/chat document;
  • Firebase rules reject unauthorized uploads.

Troubleshooting

ProblemFix
missingFileUriCheck the caller passes uri, path, or source from the picker/camera result.
imageTooLarge or videoTooLargeCompress media or adjust limits only after reviewing upload cost and timeout risk.
Network request failed during uploadCheck Firebase Function URL, device network, HTTPS, CORS/server handling, and Blaze plan.
Upload succeeds but post is missingDebug the feature's final Firestore write after upload.
Works locally but fails in releaseCheck Firebase config files, Storage rules, Functions region, and production bundle/package IDs.