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

Bob N. bobn at rogers.com
Wed Jul 27 17:38:39 UTC 2011


FWIW: I tried saving the contents of the JSStream string directly in Pharo
and I get an invalid PNG file.

| string |
string := 'data:image/png;base64... '. "long string from toDataURL()"
(FileStream newFileNamed: ('c:\data\sketchpad_test.png')) binary nextPutAll:
string base64Decoded

Bob

On Wed, Jul 27, 2011 at 4:19 AM, Johan Brichau <johan at inceptive.be> wrote:

> I also responded this on stack overflow.
>
> Depending on how you want your website to behave, I guess there are
> multiple ways of doing it. Here is the raw sample of one possibility I can
> think of using a jQuery ajax callback:
>
> html jQuery ajax
> callback: [:value | (FileStream newFileNamed: 'test.png') nextPutAll: value base64Decoded ]
> value: (JSStream on: 'canvas.toDataURL()')
>
> I did not test this myself. Maybe the filestream needs to be sent the
> #binary message to make a correct png file. Let me know if there are
> troubles.
>
> Hope it helps.
> On 26 Jul 2011, at 22:01, Bob N. wrote:
>
> (I also posted this in stack overflow)
>
> I have an image that users can annotate on the browser. I can access the
> image using
>     canvas.toDataURL()
> ...I'd like to add a 'save' option for the user to save the image on the
> server.
>
> This question has been answered for php...
>     file_put_contents('test.png', base64_decode(substr($data, strpos($data,
> ",")+1)));
> ...what I need is a Seaside callback with the PNG file contents.
>
> Is there a way to do this in Seaside?
>
> Thanks,
> Bob
> _______________________________________________
> 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/3d618942/attachment.htm


More information about the seaside mailing list