Skip to content

Instantly share code, notes, and snippets.

@dch
Created January 30, 2011 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dch/802760 to your computer and use it in GitHub Desktop.
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
// 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
}
}
}
@dch
Copy link
Author

dch commented Feb 3, 2011

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment