Skip to main content

Backend Quickstart

Use this guide to upload images from a backend service, import images from remote URLs, and issue upload tokens for signed frontend uploads.

Astronaut mechanic working under an open rocket engine hood with a boombox and dog nearby

The examples use Node.js first because @imgwire/node is the most common starting point for server-side web apps. Each section also includes Python, Ruby, and Go tabs with the same workflow.

Before you start

Complete the setup guide first so you have an Imgwire account, organization, and Environment.

For backend code, create a Server API Key and store it in a server-only environment variable such as IMGWIRE_API_KEY. Server keys can manage backend resources and create upload tokens. Do not ship a Server API Key to browser code, mobile apps, or public static bundles.

Create API Key dialog with Server Key selected in the Imgwire dashboard

Create a Server API Key from the Imgwire dashboard API Keys page.

Install a server SDK

yarn add @imgwire/node

Configure the client

Create the SDK client once and reuse it in your route handlers, workers, and background jobs.

import { ImgwireClient } from '@imgwire/node';

export const imgwire = new ImgwireClient({
apiKey: process.env.IMGWIRE_API_KEY!,
});

Upload from the filesystem

Use filesystem uploads when your backend already has the image bytes. Common examples include admin imports, background jobs, server-side image generation, scheduled media migrations, and files your backend receives from a private source.

The upload helper returns the created image record. Image records include URL helpers so your backend can generate transformed CDN URLs after upload.

import fs from 'node:fs';
import { imgwire } from './imgwire';

const image = await imgwire.images.upload({
file: fs.createReadStream('uploads/hero.jpg'),
mimeType: 'image/jpeg',
purpose: 'marketing hero image',
customMetadata: {
source: 'server-import',
},
});

const deliveryUrl = image.url({
preset: 'medium',
format: 'auto',
quality: 'auto',
});

console.log(image.id);
console.log(deliveryUrl);

Upload from a remote URL

Use URL uploads when the image already exists at a temporary or public asset URL. This is useful when working with AI image-generation platforms such as GPT Images, where the generation API returns a temporary asset URL that your backend can hand to Imgwire for ingestion.

In this flow, your backend sends the source URL to Imgwire. Imgwire fetches the source image and creates an Imgwire image record for future CDN delivery and transformations. File name and MIME type fields are optional overrides; omit them unless your app needs to force those values.

import { imgwire } from './imgwire';

const generatedAssetUrl = 'https://temporary-assets.example.com/image.png';

const image = await imgwire.images.uploadViaUrl({
url: generatedAssetUrl,
purpose: 'ai generated documentation image',
customMetadata: {
source: 'gpt-images',
},
});

console.log(image.id);
console.log(image.url({ preset: 'medium' }));

Issue upload tokens for signed frontend uploads

Signed uploads let your frontend use a publishable Client Key while your backend decides who is allowed to upload. Your frontend calls your backend, your backend checks the current user or request context, and your backend returns an Imgwire upload token.

Return the token using the shape expected by the frontend SDK examples:

{
"uploadToken": "..."
}

For a full Next.js route example, see issuing Imgwire upload tokens from a Next.js API endpoint.

import { imgwire } from './imgwire';

export async function issueImgwireUploadToken() {
// Authenticate the user and validate upload permissions here.
const uploadToken = await imgwire.images.createUploadToken();

return {
uploadToken: uploadToken.token,
};
}

Next steps

  • Use the Frontend Quickstart to connect signed upload tokens to browser or mobile uploads.
  • Review the Transformations API overview when your backend needs to generate custom CDN URLs.
  • Use server-side URL uploads for generated images, imports, and media migration jobs where Imgwire should fetch the source asset directly.

Last updated at: May 9, 2026