Implement monger.gridfs.GridFSInputFileFactory for java.io.File instances
This commit is contained in:
parent
ced9b50153
commit
7da99d98a3
2 changed files with 14 additions and 2 deletions
|
|
@ -5,7 +5,7 @@
|
|||
(:use [monger.conversion])
|
||||
(:import [com.mongodb DBObject]
|
||||
[com.mongodb.gridfs GridFS GridFSInputFile]
|
||||
[java.io InputStream]))
|
||||
[java.io InputStream File]))
|
||||
|
||||
;;
|
||||
;; Implementation
|
||||
|
|
@ -56,6 +56,10 @@
|
|||
(extend-protocol GridFSInputFileFactory
|
||||
String
|
||||
(make-input-file [^String input]
|
||||
(.createFile ^GridFS monger.core/*mongodb-gridfs* ^InputStream (io/make-input-stream input { :encoding "UTF-8" })))
|
||||
|
||||
File
|
||||
(make-input-file [^File input]
|
||||
(.createFile ^GridFS monger.core/*mongodb-gridfs* ^InputStream (io/make-input-stream input { :encoding "UTF-8" }))))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,10 +33,18 @@
|
|||
(is (= 1 (count (gridfs/all-files))))))
|
||||
|
||||
|
||||
(deftest test-storing-files-to-gridfs-using-file-instances
|
||||
(let [input (io/as-file "./test/resources/mongo/js/mapfun1.js")]
|
||||
(is (= 0 (count (gridfs/all-files))))
|
||||
(gridfs/store (gridfs/make-input-file input)
|
||||
(.setFilename "monger.test.gridfs.file2")
|
||||
(.setContentType "application/octet-stream"))
|
||||
(is (= 1 (count (gridfs/all-files))))))
|
||||
|
||||
(deftest test-storing-bytes-to-gridfs
|
||||
(let [input (.getBytes "A string")]
|
||||
(is (= 0 (count (gridfs/all-files))))
|
||||
(store (make-input-file input)
|
||||
(.setFilename "monger.test.gridfs.file2")
|
||||
(.setFilename "monger.test.gridfs.file3")
|
||||
(.setContentType "application/octet-stream"))
|
||||
(is (= 1 (count (gridfs/all-files))))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue