Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
 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))
Esempio n. 4
0
 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))