Retrieve data attached to `doc` by `attach_blob`. Raises OperationFailure if `name` does not correspond to an attached blob. Returns the blob as a string.
(self, doc, name)
| 630 | # return new_file_id |
| 631 | |
| 632 | def get_attachment(self, doc, name): |
| 633 | """Retrieve data attached to `doc` by `attach_blob`. |
| 634 | |
| 635 | Raises OperationFailure if `name` does not correspond to an attached blob. |
| 636 | |
| 637 | Returns the blob as a string. |
| 638 | """ |
| 639 | attachments = doc.get("_attachments", []) |
| 640 | file_ids = [a[1] for a in attachments if a[0] == name] |
| 641 | if not file_ids: |
| 642 | raise OperationFailure("Attachment not found: %s" % name) |
| 643 | if len(file_ids) > 1: |
| 644 | raise OperationFailure("multiple name matches", (name, file_ids)) |
| 645 | return self.gfs.get(file_ids[0]).read() |
| 646 | |
| 647 | def delete_attachment(self, doc, name, collection=None): |
| 648 | attachments = doc.get("_attachments", []) |
no test coverage detected