0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Next.jsで外部URLの画像を安全に表示する方法

Posted at

背景

Next.jsを使用していて、特定の公開URLから画像を表示させたい場合があります。以下のコードではうまくいきませんでした。

<Image
  src="https://oaidalleapiprodscus.blob.core.windows.net/xxx"
/>

解決策

Next.jsの設定ファイル(next.config.mjs)を修正して、特定のドメインからの画像取得を許可しました。

/** @type {import('next').NextConfig} */
const nextConfig = {
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'oaidalleapiprodscus.blob.core.windows.net',
        port: '',
        pathname: '**',
      },
    ],
  },
};

export default nextConfig;

この設定を適用することで、以下のように画像を表示することができるようになります。

<Image
  src="https://oaidalleapiprodscus.blob.core.windows.net/xxx"
/>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?