I'm trying to paste an image from the clipboard into an <img>
tag. The source of this image is Prnt Scrn
command and not a file. This clipboard image would be in base64
format. This base64
string can be inserted into src
attribute of <img>
tag(once ctrl-v is pressed) using javascript for display purposes. This is accomplishable by using this plugin.
So the <img>
tag would be something like this:
<img id="screen_image" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABVYAAAMACAI......(long string here)"
Although, I could persist this entire string into a mongoDB collection and retrieve it back for displaying that image, my ultimate goal is to persist this image into gridFS
. Is there a way if I could interpret base64
as a file and persist it into gridFS
?
I hope I've made it clear. Comments welcome.
UPDATE: I want to maintain a common collection to store images or any file for that matter(I'm already using gridFS to persist file attachments so I do not want to create a new collection to store clipboard images). I have also tried decoding the string using window.atob()
but then I don't know how that could be persisted to gridFS