Users customize an SVG, and when they're satisfied, I want to give them the option of sharing the image on Facebook.
I know Facebook doesn't accept SVGs, so, after reading this question, I came up with the following using canvg
:
var svgText = "<svg>" + $("#canvas2").html() + "</svg>";
canvg(document.getElementById('drawingCanvas'), svgText);
var img = document.getElementById('drawingCanvas').toDataURL("image/png");
Despite the naming of .toDataURL
, img
is not then a URL (at least, I don't think it is), but a >10,000-character string that beings with data:image/png;base64,...
.
If I then try to allow the user to share the PNG on Facebook,
window.FB.ui({
href: "https://dna.land",
method: 'feed',
name: 'name',
link: "dna.land",
picture: img,
caption: 'mywebsite.com',
description: "description",
message: "message"
}, function(response) {});
the error message I get is "the parameter href" is required (which I'm clearly supplying... maybe img
is too long and the JSON is being truncated?), though I have also seen that I'm not supplying a valid URL for picture
.
How can I share the image data on Facebook?
If there's no way to do this with the raw, base 64 encoding of the PNG, I'm not averse to temporarily storing the PNG file on a server. But, ideally, I'd only store for 24 hours, or a few months, or some minor span of time, and then be able to delete it without the user's post disappearing. Is that possible?