> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ofauth.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Display media

> Read a Vault image and display it on a page.

Read a Vault photo and create a local HTML page that displays it. The API returns the image URL. Keep your access token on your server, where the Node.js script runs.

## Read a media URL

Use Node.js 22 or later. You need an access token with `vault:read`, which lets your app read Vault media. Choose a photo’s numeric media ID from a linked account shared with that token.

Clone the [Vault image example on GitHub](https://github.com/ofauth-source/example-node-vault-image) and copy its settings template:

```bash theme={null}
git clone https://github.com/ofauth-source/example-node-vault-image.git
cd example-node-vault-image
npm install
cp .env.example .env
```

Set `OFAUTH_ACCESS_TOKEN`, `OFAUTH_LINKED_ACCOUNT_ID`, and `OFAUTH_MEDIA_ID` in `.env`, then run the example:

```bash theme={null}
npm start
```

The example reads the item with `GET /v3/access/vault/media/{mediaId}`. A successful photo response contains these fields. Other fields are omitted. The image URL below is an example:

```json theme={null}
{
	"id": 123456,
	"type": "photo",
	"canView": true,
	"isReady": true,
	"hasError": false,
	"files": {
		"full": {
			"url": "https://media.ofauth.com/example-photo.jpg",
			"width": 1200,
			"height": 1800,
			"size": 240000,
			"sources": []
		}
	}
}
```

The example checks that the photo is ready and you can view it. The SDK call and checks look like this:

```typescript theme={null}
const media = await client.access.vault.media.get({ mediaId: 123456 })
if (media.type !== "photo" || !media.canView || !media.isReady || media.hasError) {
	throw new Error("Media is unavailable or still processing")
}
const full = media.files.full
// In the generated page:
element.src = full.url
element.width = full.width
element.height = full.height
```

Expect `Saved media.html for media 123456`, with your actual media ID. Open `media.html` in a browser to see the full-size photo scaled to the window. The page contains the returned display URL, not your access token. Keep the generated file out of version control.

Use `files.preview` for a preview or `files.thumb` for a thumbnail when those fields are present. Posts, messages, and videos can return different fields. Check their API reference before using this example for them.

## Refresh expired URLs

If the image stops loading, rerun `npm start` with the same `OFAUTH_MEDIA_ID` and linked account, then reload `media.html`. The script reads the same Vault item and replaces the saved display URL. Save the media ID and the linked account ID so you can request a new URL later.

If the request fails, follow its [recovery action](https://docs.ofauth.com/v3/reference/error-handling.md). If `isReady` is `false`, wait before reading the item again. If access is denied or the item is unavailable, retrying the old URL will not fix it.

![Read an item and display its returned media URL. If the URL expires, read the post, message, or Vault item again for a current URL.](https://mintcdn.com/ofauth/VVqOdSxbrh7mDF0M/images/v3/media-url-refresh.svg?fit=max\&auto=format\&n=VVqOdSxbrh7mDF0M\&q=85\&s=fd3a9f955458df49e08988c559815945)

## Save media for later

[Vault+](https://docs.ofauth.com/v3/guides/media-storage.md) is an optional convenience for galleries and content pickers. It loads saved media faster and lets you find files and thumbnails by media ID, even when they are not attached to a post, message, or story.

Add or sync the media you need, then use its ID to read the stored file or thumbnail. Your platform does not need to keep track of expiring OnlyFans URLs for these saved copies.

To attach media to new content, follow [Media references](https://docs.ofauth.com/v3/guides/media-items.md). To add a new file, follow [Upload media](https://docs.ofauth.com/v3/guides/how-to/upload-media.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.