Esempio n. 1
0
def post_attachment(pid, name):
    '''
    Given a post ID and file name, retrieve the post, find the matching
    attachment, and return the relevant file.

    :param pid: the post ID.
    :param name: the attachment name.
    '''
    attachment = get_attachment('name', name, {'_id': pid})
    digest = attachment['digest']
    return send_from_directory(get_attachment_dir(digest), digest,
                               mimetype=attachment['content_type'])
Esempio n. 2
0
def attachment(digest):
    '''
    Given an attachment digest, find a post that lists the digest in its
    `attachments` array and return the relevant file.

    :param digest: the attachment digest.
    '''
    lookup = {
        'attachments': {
            '$elemMatch': {
                'digest': digest
            }
        }
    }
    attachment = get_attachment('digest', digest, lookup)
    return send_from_directory(get_attachment_dir(digest), digest,
                               mimetype=attachment['content_type'])