def _get_attachment_content(doc_class, doc_id, attachment_id): try: doc = doc_class.get(doc_id) resp = doc.fetch_attachment(attachment_id, stream=True) content_type = doc.blobs[attachment_id].content_type except ResourceNotFound: raise AttachmentNotFound(attachment_id) return AttachmentContent(content_type, resp)
def _get_attachment_content(doc_class, doc_id, attachment_id): try: if issubclass(doc_class, BlobMixin): doc = doc_class.get(doc_id) resp = doc.fetch_attachment(attachment_id, stream=True) content_type = doc.blobs[attachment_id].content_type else: resp = doc_class.get_db().fetch_attachment(doc_id, attachment_id, stream=True) headers = resp.resp.headers content_type = headers.get('Content-Type', None) except ResourceNotFound: raise AttachmentNotFound(attachment_id) return AttachmentContent(content_type, resp)
def get_attachment_content(case_id, attachment_id): meta = CaseAccessorSQL.get_attachment_by_identifier( case_id, attachment_id) return AttachmentContent(meta.content_type, meta.read_content(stream=True))
def get_attachment_content(form_id, attachment_name, stream=False): meta = FormAccessorSQL.get_attachment_by_name(form_id, attachment_name) return AttachmentContent(meta.content_type, meta.read_content(stream=True))