[Seaside] Integrating Images on a website. Don't want to use Apache or WAFileLibrary.

Martin Kobetic mkobetic at cincom.com
Wed Apr 23 15:12:58 UTC 2008


The extension is rather trivial as you can see in the attached file-out. It should file into Squeak fine, although there 
might be some VW specific bits in it, so you may have to fix it up for it to actually work in Squeak. One not so trivial 
issue is that we're building the WAResponse with an external stream in it as the body. Seaside-Opentalk will actually 
stream the contents of the file straight into the socket, which is important if you plan to serve larger files. I don't 
know how to make the Squeak servers do that efficiently as well. The usual problem is that the entire file is read into 
memory first and only then sent out, which obviously could cause significant memory overhead and stress the garbage 
collector.

HTH,

Martin

Holger Kleinsorgen wrote:
> aditya siram schrieb:
>> I don't appear to have that class in my image. I am using the current
>> Seaside-One-Click-Experience. Is this an extension?
> 
> ah, I didn't notice this before, it's an extension in VisualWorks / 
> Seaisde-OpenTalk.
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
> 

-------------- next part --------------
'From VisualWorks®, 7.6 of March 3, 2008 on April 23, 2008 at 11:00:47 am'!


WAFileLibrary subclass: #WAExternalFileLibrary
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'SeasideForOpentalk'!

WAExternalFileLibrary class
	instanceVariableNames: ''!

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


!WAExternalFileLibrary class methodsFor: 'testing' stamp: ' 23/4/08 11:00'!

handlesFolder: aSymbol
	
	^aSymbol = #external! !

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


WAExternalFileLibrary comment:
'This class adds the ability to serve content from files external to the image.

The files go in to a subdirectory from the running directory called ''files''
The URL to access the files is: http://localhost:7777/seaside/files/external/myfile.png

Seaside protects against malicious users attempting to use ''..'' to access above the ''files'' directory.'!

!WAExternalFileLibrary methodsFor: 'accessing' stamp: ' 23/4/08 11:00'!

documentAt: aFilename ifAbsent: aBlock
	
	| fn files |
	files _ 'files' asFilename.
	(files exists and: [files isDirectory]) ifFalse: [^aBlock value].
	fn _ files construct: aFilename.
	^fn exists
		ifTrue:
			[| mimeType |
			mimeType _ self mimetypeForFile: aFilename.
			(WAResponse new)
				contentType: (mimeType ifNil: ['application/octet-stream']);
				headerAt: 'Expires' put: 'Thu, 01 Jan 2095 12:00:00 GMT';
				stream: fn readStream binary;
				yourself]
		ifFalse: [aBlock value]!

urlOf: aSymbol using: aHandler
	
	^(aHandler baseUrl)
		addToPath: 'external';
		addToPath: (self asFilename: aSymbol);
		yourself! !


More information about the seaside mailing list