Tag: Media API

  • Direct browser uploads without exposing storage credentials

    Direct browser uploads without exposing storage credentials

    How to let browsers upload large media while the application keeps control.

    Issue a narrow upload grant

    The browser asks your application for permission, then uploads to object storage using a short-lived presigned URL. The application should choose the destination key and enforce the user’s quota before signing. A presigned URL inherits the signer’s permissions, so scope the signing identity and expiration carefully.

    Confirm the object after upload

    A successful browser request does not finish the workflow. Have the client call a completion endpoint, or consume a trusted storage event, then verify the object exists and its measured size and type are acceptable. Only then move the asset from pending to processing. Record a request ID so retries cannot create duplicate asset records.

    Avoid predictable overwrite paths

    An upload to an existing object key can replace that object. Generate opaque keys instead of using the original filename as the storage key. Keep the human filename as metadata after validation. Expire unused upload grants and clean up abandoned pending objects with a lifecycle policy.

    A concrete acceptance test

    Request an upload grant as one user, try it with an oversized file, and attempt a second upload to the same key. Confirm that the grant cannot overwrite an already published asset. Run this test with a realistic asset and record the observed state, output URL, and failure reason.

    Implementation check

    • Sign only a generated key for an authorized user.
    • Verify size and type after storage confirms the upload.
    • Expire abandoned grants and clean up pending objects.

    Related guides

    Primary reference: Official documentation.

    Related field note

    Continue with A migration plan for direct browser uploads.

  • A developer’s guide to media pipelines

    A developer’s guide to media pipelines

    A practical map from browser upload to reliable image and video delivery.

    Map the lifecycle

    A media pipeline starts before the file reaches storage. The client needs a safe way to send bytes, the server needs an identity for the asset, workers need repeatable jobs, and delivery needs URLs with predictable behavior. Treat the original as an immutable input. Derivatives are outputs that can be recreated when requirements change.

    Choose boundaries that survive change

    Separate upload authorization, object storage, processing, metadata, and delivery. A product that only accepts small profile photos may process synchronously. Large video uploads, multiple renditions, or moderation usually justify a queue and an explicit processing state. Store the asset ID, owner, source key, checksum, status, dimensions, and derivative references in a database; keep binary bytes in object storage.

    Design for retries

    Give every processing job an idempotency key tied to the asset and recipe version. A retry should find the existing output or safely replace it. Publish an asset only after required derivatives exist, then make the delivery URL visible to the application. Keep failure states observable so a missing thumbnail does not silently become a broken page.

    A concrete acceptance test

    Upload a source image, force one worker failure, and confirm that a retry produces one ready asset with no duplicate derivative. Then change the recipe version and verify that the original remains unchanged. Run this test with a realistic asset and record the observed state, output URL, and failure reason.

    Implementation check

    • Keep the source immutable and give each derivative a recipe version.
    • Move the asset to ready only after required outputs pass validation.
    • Correlate upload, processing, and delivery logs with one asset ID.

    Related guides

    Primary reference: Official documentation.

    Related field note

    Continue with Designing queue backpressure for human and agent operators.