[Seaside] How-to upload and view image ?
Andreas Nilsson
wahboh at mac.com
Sat Sep 11 14:49:53 CEST 2004
I just went through this so I'll try to explain what I did to get it
working:
First the upload form:
html attributeAt: 'enctype' put: 'multipart/form-data'.
html form: [
html fileUploadWithCallback: [:file | picture := file contents ].
html submitButton.
].
You get a WAFile in the block parameter so you can look in that class
for ideas, among other things it contains the content type.
Then to display the picture you have to wrap it in a class that
responds to #height, #width, #asMIMEDocument and returns unique values
in #= and #hash for different pictures (otherwise the images will be
cached, ie. they will not change when you change the contents of your
wrapper instance). #height and #width are just used for displaying so
they don't have to match the pictures properties, but it will strech /
shrink if they don't.
I implemented asMIMEDocument in the following way in my wrapper class
(APicture):
#asMimeDocument
^ MIMEDocument contentType: 'image/jpeg' content: contents.
Where contents is the contents from the form above that I passed to the
wrapper instance when I created it.
Then to display it you just pass an instance of your wrapper class
(APicture) to html's #imageWithForm method:
html imageWithForm: picture
Hope that helps!
/Adde
On 2004-09-11, at 14.28, Hilaire Fernandes wrote:
> Hello,
>
> I am a total newbie both to Seaside and Squeak (and more generaly to
> Smalltalk).
>
> I try to figure out how an user can upload an image into Seaside, then
> how to use it in web page rendering.
>
> A code example to understand that will be more than enought.
>
> I saw the WAUploadTest class but I miss the second part where you want
> to use
> the uploaded image to render the image in a web document.
>
> Thanks
>
> Hilaire
> _______________________________________________
> Seaside mailing list
> Seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/listinfo/seaside
More information about the Seaside
mailing list