Skip to main content
@nuxt/image already knows how to talk to a CDN through a provider. This guide covers both directions: a custom provider that points <NuxtImg> at files already in a PixGlory CDN project, and a Nitro server route that presigns and confirms new uploads.

Before you start

You need a PixGlory API key and a CDN project. See the Quickstart to create a key, and create a project from your dashboard if you don’t have one yet. Add your key and project id to your runtime config:
.env
Find your project’s id and its publicUrl (the base for the third value above) with a request against GET /v1/projects:
nuxt.config.ts

Serve files that are already in PixGlory

A provider is a pure URL builder: PixGlory has already produced the final bytes, so the provider just needs to compose the path onto your project’s base URL. There is nothing left for @nuxt/image to transform, so the provider declares that up front.
providers/pixglory.ts

Upload new files from a Nitro server route

Presign and confirm from a server route so your API key never reaches the browser. The PUT to R2 still happens client-side, straight to the presigned URL.
server/api/pixglory/presign.post.ts
server/api/pixglory/confirm.post.ts
From the client, presign, PUT the bytes, then confirm:
composables/use-pixglory-upload.ts
confirmed[0].publicUrl is the file’s permanent, canonical PixGlory link. Persist it rather than reconstructing it from the path yourself, since that’s the only URL form the API guarantees.
A single presign request can name several files at once (files: [...]), and uploads comes back in the same order. Batch a gallery upload into one call instead of one round trip per file.

Handling errors

A 402 response means the organisation’s storage quota would be exceeded; a 429 means you’ve hit the rate limit and should back off using the Retry-After header. Every error body has the same shape:
Branch on error.code, not error.message, which can change wording without notice. The full list of status codes and error codes is in the API Reference tab.