swiftimg

Next.js image hosting: a working next/image example

Use a public image URL with Next.js Image. Start with the runnable sample below, then replace its URL and dimensions with your own upload.

Try swiftimg freeSee the API

Heads-up

The default Next.js loader fetches and optimizes images through your Next.js host, so that host's image charges can still apply. The unoptimized option serves the source directly but does not generate responsive variants. Public embeds must use public images.

Step by step

  1. 1. Allow the image source

    This example uses our own editor screenshot on swiftimg.com. Allow that exact path and the delivery paths used by your uploads. Restart Next.js after editing the config.

    next.config.mjs
    // next.config.mjs
    export default {
      images: {
        remotePatterns: [
          { protocol: "https", hostname: "swiftimg.com", pathname: "/marketing/basic.png", search: "" },
          { protocol: "https", hostname: "i.swiftimg.com", pathname: "/**", search: "" },
        ],
      },
    };
  2. 2. Render a real public image

    Save this complete component as app/page.tsx. The example image is 1392 × 745 pixels. After uploading your own image, use the returned directUrl and its actual width and height, not the viewer page URL.

    app/page.tsx
    import Image from "next/image";
    
    export default function Page() {
      return (
        <main>
          <h1>Our image editor</h1>
          <Image
            src="https://swiftimg.com/marketing/basic.png"
            width={1392}
            height={745}
            alt="Swiftimg editor with crop, rotation and export controls"
            sizes="(max-width: 960px) 100vw, 960px"
            style={{ width: "100%", maxWidth: 960, height: "auto" }}
          />
        </main>
      );
    }
  3. 3. Choose who optimizes the image

    Keep the default loader for Next.js optimization. For a pre-sized image, animated GIF, or static export without an optimizer, add unoptimized to Image. It then uses the source URL directly. Resize before upload with the free editor if needed. Do not put API keys or signing secrets in a client-side loader; advanced signed transforms must be generated on your server using the documented API.

    Direct delivery option
    <Image
      unoptimized
      src="https://swiftimg.com/marketing/basic.png"
      width={1392}
      height={745}
      alt="Swiftimg image editor"
    />
  4. 4. Check the result

    Open the page and inspect the image request in your browser Network panel. Default optimization uses /_next/image; unoptimized uses the source URL. A 400 response usually needs a remotePatterns check. A 404 needs the exact returned directUrl. A private image requires authorized access and is not a public embed. Verify the layout at narrow and wide screen sizes.

Reference: Next.js Image documentation. Use the free editor for a pre-sized image or the API documentation for server-generated signed transforms.

Next.js — FAQ

Does external hosting remove Next.js optimization charges?

No. With the default loader, Next.js still optimizes the remote source. Using unoptimized bypasses that optimizer but also gives up its generated sizes and formats. Check both hosting plans for their limits.

Can I use output: 'export'?

Use unoptimized for this example when using static export. The default Next.js optimizer needs a server. A supported external loader is another option, but never expose signing secrets in browser code.

Can I mix local and hosted images?

Yes. Use local /public paths or imported files for local assets, and public direct URLs for hosted assets. Set accurate dimensions or an appropriate fill layout.

Go ad-free with Pro

Remove ads & unlock more — from $3/mo.

See Pro

See also

Hosting for Next.js works on the free plan — see swiftimg pricing and plan limits for what each tier includes, or read the image hosting API documentation to upload from your own code instead of the browser.

Ready to host your Next.js images?

Browser uploads and API access are available free. Paid plans add higher limits; Developer and Business include signed transforms and custom domains. Commercial use requires Business.