0

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

Vineeth Pradhan
  • 8,201
  • 7
  • 33
  • 34
  • I think I have made **many** comments/answers on this before. But [GridFS](http://docs.mongodb.org/manual/core/gridfs/) is **not** the "go to" method for simply storing files. But all you seem to want here is "decoding" base-64 input. So surely "google" was of help here. No? If not my comment, which should be **very** helpful. See [here](http://stackoverflow.com/a/22574469/2313887) for an example. – Neil Lunn Mar 24 '14 at 11:42
  • What problem have you encountered and where are you specifically needing help? Saving a string containing base64 encoded data would be no different than any other string. – WiredPrairie Mar 24 '14 at 12:22
  • @Vineeth did you got any solution, please post it may help me,others – Rahul Matte Apr 13 '16 at 07:53
  • @ng-rahul: I didn't know if this question was still alive! Anyway, its been 2 years since I asked this question and I unfortunately don't remember what the solution was. Probably, I didn't find an exact solution to the question I asked. If I had found a solution by myself, I probably would've posted the answer to it by myself – Vineeth Pradhan Apr 13 '16 at 10:24
  • @ng-rahul: Although, I vaguely remember just storing the `base-64` string in the collection just like any other string. I just can't confirm because I don't remember :( – Vineeth Pradhan Apr 13 '16 at 10:25

1 Answers1

0

I'm using Mongo for my senior project right now and previously I was storing child (client is a local non profit like world vision) pictures with GridFS but recently I've moved to storing them in the actual child doc in base64. All of the images are around 3mb and base64 converts out to mostly 4-5mb. If you can store them as base64 it makes for a much simpler schema, I think.

I know you said you wanted to use GridFS, but I would only go that route if you have files over 16mb. For what I hope are obvious reasons it's much simpler to just store them as strings in docs.

Joshua
  • 21
  • 4