views:

1223

answers:

3

I'm trying to create and retrieve a BLOB in a MySQL table via Kohana's ORM library.

The code looks something like:

$attachment = new Attachment_Model();
$attachment->name = $info['FileName'];
$attachment->size = strlen($info['Data']);
$attachment->data = $info['Data'];
$attachment->mime_type = $info['content-type'];
$attachment->save();

I've verified that the data is OK at this point by outputting it to a file. However, when I retrieve the data it comes out corrupted. I've managed to narrow this down a bit more - I've used the MySQL query tool to extract the data as held in the database and I can verify that the data in the database is corrupt, so the problem must be on the INSERT.

Also, the files inputted aren't always corrupt - smaller files (such as images) tend to be OK.

Anyone have any ideas?

A: 

Wild guess, but: probably because the kohana model layer inserts all data as character data instead of binary, which will cause you troubles when saving/retrieving BLOB objects.

thr
+2  A: 

It turns out that, in this case, I was using the BLOB data type.

The BLOB data type truncates data at 65535 characters (silently, without throwing an error!)

I've upped it to a MEDIUMBLOB (which has a max length of 16777215 characters), and it seems to work OK!

Phill Sacre
A: 

Could you please pase whole model and controller code?

Spyro