1

I have some graphics made with canvas that I want to save in a specific folder of the user's computer as a .png image.

I'm doing this on the client side:

$(".new_canvas").each( function(index) {

                var dataurl = $(".new_canvas")[index].toDataURL("image/png");

                $.ajax({
                        type: "POST",
                        url: "export_images",
                        data: dataurl,
                        }
                });
            });

On the server side I receive the base64 encoded string but how can I save this image in a specific directory?

I already saw some questions about this and tried a few things but with no success...

Thank you.

Neuza
  • 117
  • 3
  • 13
  • Can you give us at least one of the examples that you tried? – jeschafe Jul 19 '12 at 16:26
  • I tried this: http://stackoverflow.com/questions/11112321/how-to-save-canvas-as-png-image and – Neuza Jul 19 '12 at 16:48
  • You're posting to the server side, and yet you're talking about saving a file to the client side? Where *do* you want to save this file? – JayC Jul 20 '12 at 03:08
  • This is a web based application, however it's installed on the user computer, not accessed by a browser. So really the server is on the user's machine. I'm already saving a .xls file in a specific directory like this, but I don't know how to do this with an image because of the encoding (I think)... I actually can save the file to the directory but it's corrupt and I can't see the image. – Neuza Jul 20 '12 at 08:29

1 Answers1

1

save in a specific folder of the user's computer

Oh dear. You absolutely cannot do this. The best you can do is present an image for download from the server, which will go into a download directory, or you can offer a link. You cannot specify where you want a file saved on a user's computer.

Simon Sarris
  • 62,212
  • 13
  • 141
  • 171
  • I can... I did this already, I saved the file to a directory but the file didn't had the image because I don't know if there's a specific way to encode and save it... – Neuza Jul 20 '12 at 08:36
  • wait, do you mean saving the file on the server? – Simon Sarris Jul 20 '12 at 13:39
  • yes. the application is installed locally on the user's machine (i don't have many users, the server is on the computer). I'm using xulrunner, and have some canvas to save as png. I have the base64 string of the image (with canvas.toDataUrl("image/png")) but then I don't know how to save it properly. I need to decode it first? – Neuza Jul 20 '12 at 14:21
  • Yeahh, it depends on what you can write with. PHP has the base64 decode built in. I don't know what options are available to you with xulrunner – Simon Sarris Jul 20 '12 at 14:53
  • @Neuza can you link please how you can achieve (saved the file to a directory) – Abdul Hameed Feb 23 '17 at 09:34