Luchezar Luchezar - 1 year ago 46
HTML Question

Saving a lot of canvas images to server

I have a script that generates about 250 images from

My question is how to save them all at once (one request to server) instead of posting them individually.

I need a way to pack them in single request and then send them to PHP server for unpacking.


canvas.toDataURL() gives the byte data encoded in base64, they are safe to be used as strings and passed through HTTP.

do something like:

var images = [];
while(....) {
var imagesJson = JSON.stringify(images);
// pseudo code of jQuery ajax, you can make use of form and a hidden field 
// or any other way you'd like to query the server

with PHP (other server side languages should almost be the same):

$images = json_decode($_POST['images'], true);
foreach($images as $image) {
    $image = base64_decode($image);
    file_put_contents('<path to file>', $image);