Geo
Geo

Reputation: 96767

Can I serve generated images without storing them on the server side?

I have a form where the user uploads two images, and based on them I generate about 10 other images ( using PIL ). The thing is, I want to show an HTML page that contains all the generated images, but I would like not to have to store them on server side. Is this possible?

Upvotes: 2

Views: 318

Answers (2)

wal-o-mat
wal-o-mat

Reputation: 7344

You need to design your URLs correctly and have a view for an URL pointing to an image. In that view then you send the generated image. The Django website has an example for a PDF.

https://docs.djangoproject.com/en/1.3/howto/outputting-pdf/

In your (static?) HTML page you have a reference then like

<img src="/dyn_images/foo.png"/>

and an URL rule watching for that.

Upvotes: 1

jro
jro

Reputation: 9474

You could use the Data URI scheme. The examples section on that Wikipedia article has some nice things to start with. What you need then, is to convert the binary image data to base64 so you can include it on your page. Fortunately, there are scripts available for this already.

Browser support seems okay, all major browser have no problem with it. For IE, it is supported from IE8 upwards (with IE8 having a limitation of 32KiB for the URI size).

Upvotes: 2

Related Questions