oakserver / oak

A middleware framework for handling HTTP with Deno, Node, Bun and Cloudflare Workers 🐿️ 🦕

Home Page:https://oakserver.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I send multiple images from oak to a browser client?

M3cubo opened this issue · comments

I have a frontend page, let's say it contains a gallery. Every image in the gallery is a file that I have in my server (not in the public directory), so I can use .fetch(), to request them from Oak as blobs and turn them into images.

But If I have many images, how should I request these from the browser? With multiple fetch's in the client side?

On the server, I suppose I could write an oak route like this:

 Router.get(["/images/:image_ID"], async (context) => {

  let myBlob = getImageBlobFromID(context.params.image_ID)
  context.response.body = myBlob;

}); 

...and call it many times. Theoretically and practically speaking, is that how I should do it?

(and let's assume I have not created an automatic spritesheet with all the images of that gallery)