Search code examples
javascriptsvgsavefilesystemslocal

How to save svg canvas to local filesystem


Is there a way to allow a user, after he has created a vector graph on a javascript svg canvas using a browser, to download this file to their local filesystem?

SVG is a total new field for me so please be patient if my wording is not accurate.


Solution

  • It might be possible using the regular "Save" browser command, but it won't just save the SVG canvas, it will save the whole page.

    I believe your best bet is to use AJAX and send the whole SVG XML data as POST data to a server script, and have that script just send back the POST data with the header Content-Disposition: attachment; filename=yourfile.svg.

    (Under PHP, you can get the raw POST contents with file_get_contents('php://input').)