I have a contenteditable section... if someone copy-and-pastes a picture, what's the best way for me to post it on my end?
I'm using jQuery, PHP, and Perl, so I can work within any of those.
I'm pretty sure that it will come through as a data URI, like this:
but I'm not sure if these are browser specific or what. And, obviously, these would load inline instead of calling a separate HTTP connection (maybe a good thing?), and wouldn't cache (maybe a bad thing). But they would be compressed via GZIP, so maybe it's worth the trade off of not caching?
So what do you guys and gals think, should I just allow these as-is, or should I try to find a way to upload the image to the server and link to it with a regular <img...>
If I try to turn it in to an actual image, I'm thinking it would just be something like this in Perl... ?
$id = $id_of_post_being_submitted;
$image = $ext = $post_being_submitted;
$image =~ s#src=("|')(data:image/.+?)\1#$2#;
$ext =~ s#data:image/([^;]+)#/$1/;
open $fh, '>' . $id . '.' . $ext or die $!;
print $fh $image;
$post_being_submitted =~ s#src=("|')(data:image/.+?)\1#src="https://example.com/$id.$ext"#;
I just typed that for the example, of course, it's not tested or anything. And it doesn't allow for multiple images in the same post, anyway, so it's just a starter idea...