Store Nano Banana (Pro) Images on a CDN - Google Image Generation

Back to Blog
Lukas Gisder-Dubé
2 min read
Nano BananaGoogle AIGeminiAI Image GenerationImage UploadCDNContent Delivery Network

Generate Images with Google Gemini and Store Them on a CDN

Nano Banana (Pro) is a weird name, but it's a great AI image generator. You can create stunning photorealistic images for your projects. The Docs show how to store them on your local machine, but what if you want to use them in production environments?

Let's start with the script to generate images using Google's GenAI SDK.

ts
import { GoogleGenAI } from '@google/genai'

const ai = new GoogleGenAI({ apiKey: process.env.GOOGLE_API_KEY! })

const response = await ai.models.generateContent({
  model: 'gemini-2.5-flash-image',
  contents: 'Generate an image of a tiny banana wearing sunglasses',
})

console.log(response)

The official docs have an example on how to turn the response into a buffer and then store them locally. This might work when playing around a bit, but if you actually want to serve the image(s) to users, you'll need to upload them to a CDN. Let's see how quickly you can do this with easyCDN.

easyCDN's Node.js SDK provides a method to upload images directly from the Gemini response. Simply pass the response to the uploadFromGoogleAi method and you're good to go:

ts
import { createClient } from '@easycdn/server'
import { GoogleGenAI } from '@google/genai'

const easyCdnClient = createClient({
  secretKey: process.env.EASYCDN_SECRET_KEY!,
})

const ai = new GoogleGenAI({ apiKey: process.env.GOOGLE_API_KEY! })

console.log('Generating images with Gemini...')

const response = await ai.models.generateContent({
  model: 'gemini-2.5-flash-image',
  contents: 'Generate an image of a tiny banana wearing sunglasses',
})

console.log('Uploading images to easyCDN...')

// Upload all images to easyCDN
const uploadedAssets = await easyCdnClient.uploadFromGoogleAi(response)

console.log('Done! Uploaded assets:')
for (const asset of uploadedAssets) {
  console.log(`- ${asset.asset.name}: ${asset.asset.url}`)
}

The uploadFromGoogleAi method automatically extracts all images from the Gemini response and uploads them to your easyCDN bucket. No need to parse through the response structure yourself.

While uploading to easyCDN, you can make use of image transformations or set expiry dates on the uploaded images. You can find all options in the docs.

Now you're ready to serve the image(s) to your users. You can automate any kind of image generation process and be confident that the images are stored on a CDN and can be served quickly and efficiently.

Happy uploading!

Ready to host your assets?

Create your free account and start serving your assets in minutes.

No credit card required • Get started in under 2 minutes