I wrote the site in JavaScript and HTML5. It generates an image inside the canvas, and can save them to a computer. I want to add a button - to share in VKontakte

I found js for sharing content http://vk.com/js/api/share.js , and I also have this code on my site for saving images

function download() { //upload var dt = canvas.toDataURL('image/jpeg'); this.href = dt; }; downloadLnk.addEventListener('click', download, false); 

but I could not understand how to tie it together. I ask for advice on the implementation of loading canvas in VK. can i do without php? what about google itp

there are such thoughts, but so far I have no particular idea what to do next

 <canvas id="myCanvas" width="578" height="200"></canvas> <script> var canvas = document.getElementById('myCanvas'); var context = canvas.getContext('2d'); // begin shape context.beginPath(); context.moveTo(170, 80); context.bezierCurveTo(130, 100, 130, 150, 230, 150); context.bezierCurveTo(250, 180, 320, 180, 340, 150); context.bezierCurveTo(420, 150, 420, 120, 390, 100); context.bezierCurveTo(430, 40, 370, 30, 340, 50); context.bezierCurveTo(320, 5, 250, 20, 250, 50); context.bezierCurveTo(200, 5, 150, 20, 170, 80); // complete custom shape context.closePath(); context.lineWidth = 5; context.fillStyle = '#8ED6FF'; context.fill(); context.strokeStyle = 'blue'; context.stroke(); //Convert canvas image to URL format (base64) var dataURL = canvas.toDataURL(); // Send it to server $.ajax({ type: "POST", url: "script.php", data: { imgBase64: dataURL } }).done(function(o) { console.log('saved'); }); </script> 

I read it https://vk.com/dev/photos.saveWallPhoto

    1 answer 1

    You cannot send any image to VKontakte (it doesn't matter whether it is drawn on canvas or a regular jpeg-file) using JavaScript due to CORS restrictions. You must send an image to your server and form a request already there.

    I also want to warn you that you will not be able directly from your server to post an image on the user's wall. Applications like "web site" can send posts to the wall only through the Open API (before the post is published, the user opens a confirmation window).

    The course of action should be as follows:

    1. Create an album through the server.
    2. Upload a picture through the server.
    3. On your site using the Open API call the wall.post method.