I think the best way to achieve this is to physically file in some shared folder on your server. It should be accessible in such a way that you will need to use something like
http://www.myhost.com/images/my/path/to/image.jpg
You can still save the Base64 image in mongodb as a backup, however this is not the best way to get your images due to performance issues (as you saw). I recommend you do the following:
Each time you store an image on mongo, be sure to save the "image file" as yourself in some public place on your server. Keep in mind that you must save the path to this file on the mongo model you are using. So, the next time you call the object, and not get the image of base 64, you should only get the path to the image.
Let's say you have this model
myModel = { name: "some name", image64: "someextralongstringveryveryveryweird......", imageUrl: "/images/my/path/to/image/imagename-id.jpg" }
at the next request on it, you can simply ignore image64 using the mongo projection, and on your client side you just use some html tag that uses this URL.
<img src="/images/my/path/to/image/imagename-id.jpg">
This will help you achieve great results.
There are several libraries that could help you manage image creation. ImageMagick is the one I used and is so versatile.
source share