PATH |
It is often useful to serve images from the database through the Web application server instead of storing copies of the images in the Web server's document directory. WebObjects 4.0 adds enhancements to WOImage and WOActiveImage to ease this process.
In the EOModel for the Movies example database, the TalentPhoto class has a photo attribute that stores an NSData representing the photograph image of an actor or director. You can use recent enhancements to the WOImage component to display the image of the actor in an application. This example uses the new data and mimeType bindings to accomplish this.
The following steps illustrate how to add database-stored images to an application. The example uses the Movies EOModel and a Wizard-generated application. To prepare the example, perform the following steps:
To add the image, perform the following steps:
Open the Main.wo component in WebObjects Builder.
In the data field, enter talentDisplayGroup.selectedObject.photo.photo
For mimeType , select image/gif.
In this example, the data in the database is assumed to be a GIF image. If different image types are stored, you could create an accessory on the class that either stores the type or determines it on-the-fly and returns the appropriate MIME type.
It is also possible to serve images created on-the-fly by the application. Bind the data attribute to a method returning the dynamically generated image. For an example of this, see the CreatePlots example in the Developer/Examples/WebObjects/WebScript folder.
22 July, 1998. Timothy Joransen. First Draft.
19 November, 1998. Clif Liu. Second Draft.