So i have a program that involves generating an image with the image crate, and I wanted to integrate the program into a website/server using rocket, currently I have my program returning a Vec of the image bytes. I was wondering if there was any way that I can take the bytes, or as a DynamicImage from the image crate, and display it (or allow it to be downloaded) from a server/site that uses rocket. I know I could save the bytes to a file and have the response be a NamedFile, but it would make me uncomfortable to let the web server download files onto my system.
Think about how website client-side resources work: PNGs, HTML files, JS, WASM files, are all exactly that: files.
Why does it make you uncomfortable? It's a core functionality of servers in general, all the way back to the HTML protocol itself.
If the webserver generates a resource and a client needs to access it, that's generally the way to go.
To play devil's advocate: in principle it should be possible to stream the image bytes to the client directly using eg a WebSocket. But how client-side code would turn that into a resource that can actually be used, I don't know. So you'd have to solve that problem.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.