Re: Blobs

Kieran Kelleher <[email protected]>
Newsgroups gmane.comp.web.webobjects.devel
Message-ID <[email protected]>
Pick a blob size that suits. I use mediumblob for user uploaded  
images. Look at mysql docs to see the bytesize for each type. In /etc/ 
my.cnf you need to set a property for the maximum blob size.... by  
default, it may be too small. See the example my.cnf files supplied  
in the MySQL installation.

The blob simply maps to type NSData. So you can just use setMyImage 
( NSData anImage ); or takeValueForKey as with any object. NSData can  
be constructed form a Stream.

For form upload, use WOFileUpload and it has bindings it sets for you  
such as the final file path and the mime type which you can grab.  
Store the mime type in the db with the image for use in WOImage or  
for headers in direct action responses to imageID. See Apple  
WebObjects examples for WOFileUpload in your Developer folder.
Gotchas:
1) Don't forget to set enctype on the form.
2) When editing an image object, override takeValuesFromRequest and  
only set the image if a new one was actually updated. if you bind  
directly, then your existing image will be nulled when someone edits  
an existing EO.

Here is example of a table for images:

CREATE TABLE `image` (
   `content` mediumblob,
   `mimetype` varchar(255) default NULL,
   `oid` int(11) NOT NULL default '0',
   `pixelheight` int(11) default NULL,
   `pixelwidth` int(11) default NULL,
   PRIMARY KEY  (`oid`)
) ENGINE=InnoDB;

That's all I can think of from top of my head (pixel measurements are  
optional ...... use one library or another to get this info form  
uploaded image. I like sips (do 'man sips' on the command line)

Cheers, Kieran

On Apr 26, 2007, at 9:26 AM, WILLIAM GARNETT wrote:

> Hello every one;
>
>
>
> I am trying to find out how to save / fetch BLOBs. (I use MySQL)
>
>
>
> I have a table of companies and I want to save each company's logo  
> as a BLOB
>  The intention is to set up a seperate table which holds only the  
> blobs, and
> set up a one-to-one relationship Company <-> Logos. (Don't want  
> BLOB fetched
> when fetching each company to avoid overhead - only want to fetch  
> BLOB when
> required).
>
>
>
> Can some one tell me how to do this please. Some sample code would  
> be great.
>
>
>
> Thank you.
>
>
>
> Cheers,
>
> Bill.
>
>
> _______________________________________________
> WebObjects-dev mailing list
> [email protected]
> http://www.omnigroup.com/mailman/listinfo/webobjects-dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.