Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document put-attachment please #76

Open
boxxxie opened this issue Jan 3, 2013 · 1 comment
Open

document put-attachment please #76

boxxxie opened this issue Jan 3, 2013 · 1 comment

Comments

@boxxxie
Copy link

boxxxie commented Jan 3, 2013

i'm getting errors with the below code.

(def test-doc-pdf {:filename (fs/base-name test-doc-pdf-path)
                   :mime-type "application/pdf"
                   :data-length (fs/size test-doc-pdf-path)
                   :data (->> test-doc-pdf-path
                                fs/absolute-path
                                io/file
                                io/input-stream)})
(couch/put-attachment documents-db (d/squuid) (:data test-doc-pdf) test-doc-pdf)

IllegalArgumentException No value supplied for key: {:filename "test_0.pdf", :mime-type "application/pdf", :data-length 3298639, :data #<BufferedInputStream java.io.BufferedInputStream@65d8015a>} clojure.lang.PersistentHashMap.createWithCheck (PersistentHashMap.java:89)

@boxxxie
Copy link
Author

boxxxie commented Jan 3, 2013

i was able to get my code working... it was completely not obvious doing so... the way keys destructuring is used in the put-attachments i haven't seen before. i has to do some ugly manipulation to my doc hash-map :(

(def documents-db (str couchdb "/documents/"))
(def test-doc-pdf-path "test/data/input/test_0.pdf")
(def test-doc-pdf {:filename (fs/base-name test-doc-pdf-path)
                   :mime-type "application/pdf"
                   :data-length (fs/size test-doc-pdf-path)
                   :data (->> test-doc-pdf-path
                                fs/absolute-path
                                io/file
                                io/input-stream)})
(defn add [doc]
                                        ;(couch/put-attachment)
  (let [couchdb-args (concat [documents-db { :_id (str (d/squuid))} (:data doc)]
                           (flatten (into [] doc)))
        ]
    (apply couch/put-attachment couchdb-args))
  )
(add test-doc-pdf)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant