I want to store images in Db4o using Blobs. How can I store them and how do I get them out again?
+3
A:
Take a look at this question answer: http://stackoverflow.com/q/3124244/209899
I repost my answer again, a bit updated with the links to the Java documentation:
There are two basic ways to handle Blobs. Either you store a blob as byte-array in the database or you use the special db4o-Blob-Type. Both have their advantages.
Advantages/Disadvantages with byte array:
- The blobs are in the db4o-database-file. So there's only a single file to copy around.
- Byte-arrays are part of the normal db4o-transaction and behave as expected.
- When storing large blobs, you might run into the database-size limitation of db4o. (256 GB)
Advantages/Disadvantaged with db4o-blobs
- The blobs are stored as regular files outside the database. This keeps the database itself small. Furthermore you just can access all stored blobs with a regular application.
- You always need to copy the blob-directory and the database.
- The db4o-blobs works outside the db4o transaction. This means that a db4o-blob behaves different than any other stored object (and the API is a little strange). However this allows to retrieve a db4o-blob without blocking the current transaction.
For your case I would store a byte[] array with the picture in the Person class. Or you create a special Image-class. This image-class contains then a byte-array with the picture. And a few methods to convert this byte-array from and to a Winforms-bitmap.
Gamlor
2010-09-12 15:44:33