[Seaside] Serving pictures from the image

Jens Pall jens at axonspace.com
Thu Jan 25 20:15:27 UTC 2007


Brian Brown wrote:
> 
> 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)]
> 

<snip>

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

Wow! This is great!

Thanks Brian

JP


More information about the Seaside mailing list