[Seaside] Serving pictures from the image
rbb at techgame.net
Thu Jan 25 19:40:55 UTC 2007
On Jan 25, 2007, at 11:04 AM, Jens Pall wrote:
> Bany, Michel wrote:
>>> Regarding the files, I am looking for a way to serve binary data
>>> from directly within the image itself, not using files on the
>>> external filesystem. I'm planning on using Magma as the
>>> persistent repository for everything and don't want to rely on
>>> stuff out on the filesystem, hence I need a way to load and serve
>>> my images completely from within squeak.
>> You may want something like this
>> (html anchor)
>> document: aByteArray mimeType: 'application/msword'
>> fileName: 'report.doc'
> Yes, this looks promising.
> But how do I load the document from disk into aByteArray? I think I
> can do this using a web form, but I want to be able to load it
> directly from the filesystem (used in a batch load later).
Here was a method I used quite some time ago for a Seaside app that
had to have the pictures in the image ;) Basically, I loaded the jpeg
files from the hard drive and put them into a class side Dictionary.
I had a singleton JPEGImages class through which I would reference
the dictionary. When I wanted to transfer things between images, I
would save the dictionary as a reference stream and could load that
in with a different message on my JPEGImages class.
Here is the import method from the JPEGimages class:
| jpegFiles thisDir |
thisDir _ FileDirectory on: pathString.
jpegFiles _ thisDir fileNamesMatching: '*jpg'.
jpegFiles do: [:ea ||fileStream |
fileStream _ thisDir readOnlyFileNamed: ea.
DictionaryOfImages at: ea put: ((JPEGImage fromStream:fileStream)
And the JPEGImage class:
Object subclass: #JPEGImage
instanceVariableNames: 'height width contents name'
^ MIMEDocument contentType: 'image/jpeg' content: self contents! !
^ contents! !
| tform |
contents _ aFileStream contentsOfEntireFile.
tform _ ImageReadWriter formFromStream: aFileStream binary.
width _ tform width.
height _ tform height.
^ self.! !
^ height! !
^ name! !
name _ aString! !
^ width! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
!JPEGImage class methodsFor: 'creation' stamp: 'rbb 7/7/2003 13:59'!
^ (self new) contents: aFileStream! !
> Seaside mailing list
> Seaside at lists.squeakfoundation.org
More information about the Seaside