Created
January 30, 2011 10:34
-
-
Save dch/802760 to your computer and use it in GitHub Desktop.
CouchDB map that provides doc id and attachment names for easy URL conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// view map for generating URLs to stubbed attachments | |
function(doc) { | |
if (doc._attachments) { | |
for (var i in doc._attachments) { | |
emit(doc._id, doc._id + "/" + i); | |
} | |
} | |
} | |
// example document | |
{ | |
"_id": "de14d389737bb89780aa32e1cd001864", | |
"_rev": "5-9ec2472a23b1267822ccfa6df3df2bcd", | |
"notes": "some notes", | |
"_attachments": { | |
"blah.txt": { | |
"content_type": "text/plain", | |
"revpos": 4, | |
"length": 28, | |
"stub": true | |
}, | |
"foo.txt": { | |
"content_type": "text/plain", | |
"revpos": 2, | |
"length": 18, | |
"stub": true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will return a k/v like this:
Key / Value
ID: one_attachment "one_attachment/README.txt"
ID: de14d389737bb89780aa32e1cd001864 "de14d389737bb89780aa32e1cd001864/blah.txt"
ID: de14d389737bb89780aa32e1cd001864 "de14d389737bb89780aa32e1cd001864/foo.txt"