[Seaside] Serving pictures from the image

Brian Brown 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:

importFromPath: pathString
	| 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)  
name: ea)]


And the JPEGImage class:

Object subclass: #JPEGImage
	instanceVariableNames: 'height width contents name'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'AbleLink-Utility-Images'!

asMIMEDocument
	^ MIMEDocument contentType: 'image/jpeg' content: self contents! !

contents
	^ contents! !

contents: aFileStream
	| tform |
	contents _ aFileStream contentsOfEntireFile.
	tform _ ImageReadWriter formFromStream: aFileStream binary.
	width _ tform width.
	height _ tform height.
	^ self.! !

height
	^ height! !

name
	^ name! !

name: aString
	name _ aString! !

width
	^ width! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

JPEGImage class
	instanceVariableNames: ''!

!JPEGImage class methodsFor: 'creation' stamp: 'rbb 7/7/2003 13:59'!
fromStream: aFileStream
	^ (self new) contents: aFileStream! !


>
> JP
> _______________________________________________
> Seaside mailing list
> Seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



More information about the Seaside mailing list