What's base64 encoding? Why would anyone do anything in base 64? Is there something I should have read?
Your original question:
Should I be able to serve .jpg files?
... was perhaps a bit vaguely worded. You can send any file you like, but the HTTP transfer protocol is basically text. You can
send other things, but they are usually base-64 encoded, which effectively turns them into text.
I suppose we assumed that since you are generating HTML pages you might know that. Ah well.
Basically you run the file (in batches) through the base64-encoder, which makes it 4/3 times larger. I think you usually do the data in batches of around 57 bytes which become 76 bytes when encoded (ie. the length of a line in an email message).
You will also need to look at the header, I think you need to tell the browser that the text is base64-encoded.
Something like this line in addition to what you have:
An example, from an email I got:
Something roughly along those lines. Look it up, there will be lots of references. And you should find a base-64 encoding function easily enough.