Save string as gridFS file

27 views
Skip to first unread message

Linus Ericsson

unread,
Jan 13, 2012, 8:21:25 AM1/13/12
to congomo...@googlegroups.com
Hi!

I'm trying to save a string as a gridFS file, but how do I coerce from string to a InputStream or similar?

Now I'm somewhere at

(def string-to-save "Hello World!")

(insert-file! :filecollection string-to-save :filename "myfile.txt") but GridFS wants a stream. 

What is the best way to convert a string to a javastream that GridFS can eat?

/Linus

josh rotenberg

unread,
Jan 13, 2012, 12:43:23 PM1/13/12
to congomo...@googlegroups.com
You should be able to store a string by getting it as a byte array.
See the tests:

https://github.com/aboekhoff/congomongo/blob/master/test/somnium/test/congomongo.clj#L383

(let [f (insert-file! :testfs (.getBytes "toasted")
:filename "muffin" :contentType "food/breakfast")]


Josh

Linus Ericsson

unread,
Jan 13, 2012, 9:22:36 PM1/13/12
to congomo...@googlegroups.com
Ah, I forgot to check the tests. Thank you! /L

2012/1/13 josh rotenberg <joshro...@gmail.com>
Reply all
Reply to author
Forward
0 new messages