Skip to Content
dimah-s3v2.8.1

Object Image

An img for a private object, with a signed URL that refreshes before it expires.

Show an image from a private bucket. ObjectImage signs an inline URL with useObjectUrl, refreshes it before it expires, and shares it with other images of the same object.

Installation

import { ObjectImage } from "@dimah-s3/ui";

Usage

"use client";

import { ObjectImage } from "@dimah-s3/ui";

export function CoverImage({ coverKey }: { coverKey: string | null }) {
  return (
    <ObjectImage
      route="covers"
      objectKey={coverKey}
      alt="Album cover"
      className="size-40 rounded-md object-cover"
      fallback={<div className="bg-muted size-40 rounded-md" />}
    />
  );
}

route must allow downloads. Its server download hooks decide who may read the object, as for any download.

Fallback

fallback shows while there is no key or URL yet, and when signing or loading the image fails.

Accessibility

alt is required. Pass alt="" when the image is decorative, such as next to a name that already describes it.

API Reference

Also accepts every img prop except src.

PropTypeDefaultDescription
routestringrequiredRoute that signs the URL
objectKeystring | nullrequiredKey of the stored object. null shows fallback
altstringrequiredAlternative text. "" for a decorative image
fallbackReactNode—Shown while there is no URL, and when the image fails
apiS3Api—Signs the URL. Optional inside S3Provider

On this page