Пример #1
0
def download(filename):
    """Download an attachment."""

    attachment = models.Attachment.query.get_or_404(filename)
    if not attachment.challenge.unlocked:
        flask.abort(404)

    return flask.send_from_directory(
        utils.attachment_dir(), filename,
        mimetype=attachment.content_type,
        attachment_filename=attachment.filename,
        as_attachment=True)
Пример #2
0
def download(filename):
    """Download an attachment."""

    attachment = models.Attachment.query.get_or_404(filename)
    if not attachment.challenge.unlocked:
        flask.abort(404)

    return flask.send_from_directory(utils.attachment_dir(),
                                     filename,
                                     mimetype=attachment.content_type,
                                     attachment_filename=attachment.filename,
                                     as_attachment=True)
Пример #3
0
 def post(self):
     fp = flask.request.files['file']
     # Hash the file
     md = hashlib.sha256()
     while True:
         blk = fp.read(2**16)
         if not blk:
             break
         md.update(blk)
     fhash = md.hexdigest()
     fp.seek(0, os.SEEK_SET)
     dest_name = os.path.join(utils.attachment_dir(create=True), fhash)
     fp.save(dest_name, buffer_size=2**16)
     return dict(aid=fhash, content_type=fp.mimetype)
Пример #4
0
 def post(self):
     fp = flask.request.files['file']
     # Hash the file
     md = hashlib.sha256()
     while True:
         blk = fp.read(2**16)
         if not blk:
             break
         md.update(blk)
     fhash = md.hexdigest()
     fp.seek(0, os.SEEK_SET)
     dest_name = os.path.join(utils.attachment_dir(create=True), fhash)
     fp.save(dest_name, buffer_size=2**16)
     return dict(aid=fhash, content_type=fp.mimetype)