[Seaside] How to save a html5 canvas.toDataURL as a png file on the server

Bob N. bobn at rogers.com
Wed Jul 27 20:37:58 UTC 2011


Thanks. Nice catch.
Adjusting the string also avoids the VW index range error in Net.MimeScanner
class>>decodeBase64From:to:in:on:

This code works in VW (with string copy hack).

html button
onClick: (html jQuery ajax
callback: [:value |
| writestream string |
writestream := ('c:\data\sketchpad_image.png' asFilename withEncoding:
 #binary) writeStream.
string := value copyFrom: 23 to: value size.
[writestream nextPutAll: (Seaside.GRPlatform current base64Decode: string)
asByteArray]
                                       ensure: [writestream close] ]
value: (Javascript.JSStream on: 'sketchpadCanvas.toDataURL()'));
with: 'Save'.

Bob

On Wed, Jul 27, 2011 at 3:16 PM, Johan Brichau <johan at inceptive.be> wrote:

> I don't have access to a smalltalk image right now, but my guess is you
> need to strip the string of the mine type declaration first. The php example
> does the same thing: it takes the substring after the comma before decoding
> and writing to the file.
>
> --
> Johan
>
> On 27 Jul 2011, at 17:43, "Bob N." <bobn at rogers.com> wrote:
>
> Thanks. Here is what I'm now using...
>
> html jQuery ajax
> callback: [:value |
> | writestream |
>  writestream := (('c:\data\sketchpad_', Time now asSeconds printString
> ,'.png') asFilename withEncoding:  #binary) writeStream.
> [writestream nextPutAll: (Seaside.GRPlatform current base64Decode: value)
> asByteArray] ensure: [writestream close]]
>  value: (Javascript.JSStream on: 'sketchpadCanvas.toDataURL()')
>
> ...but I got an exception in Net.MimeScanner
> class>>decodeBase64From:to:in:on:
>
> aString size is 17074 and the code iterates over the string, checking a
> #limit which is set to the string size. But the code checks for index + 3
> which exceeds the string size.  Hacking the code so the limit is set to size
> - 3 works, but the resulting image is not a valid PNG file.
>
> Is there is way to test the decoded content to see if it is a valid PNG
> file?
>
> I also tried toDataURL("image/jpeg") which created an output starting with
> 'data:image/jpeg;base64' but that also saved an invalid image file.
>
> Bob
>
> On Wed, Jul 27, 2011 at 10:23 AM, Philippe Marschall <<philippe.marschall at gmail.com>
> philippe.marschall at gmail.com> wrote:
>
>> 2011/7/27 Bob N. < <bobn at rogers.com>bobn at rogers.com>:
>> > Thanks Johan, feels like I almost have it.
>> > I'm doing this work in VW. Could someone show the VW equivalent of
>> > #base64Decoded? Or is it in some Seaside compatibility library? I'm
>> using
>> > 'Seaside 3.0 - 87' from the Cincom public repository.
>>
>> GRPlatform current base64Decode:
>>
>> Cheers
>> Philippe
>> _______________________________________________
>> seaside mailing list
>>  <seaside at lists.squeakfoundation.org>seaside at lists.squeakfoundation.org
>>  <http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside>
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>>
>
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
>
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20110727/bdde304d/attachment-0001.htm


More information about the seaside mailing list