Skip to content

Instantly share code, notes, and snippets.

@mehmetkose
Forked from alejandrobernardis/handlers.py
Created December 23, 2016 11:27
Show Gist options
  • Select an option

  • Save mehmetkose/2f2814763744fa4f6f935a8ce4f04c89 to your computer and use it in GitHub Desktop.

Select an option

Save mehmetkose/2f2814763744fa4f6f935a8ce4f04c89 to your computer and use it in GitHub Desktop.

Revisions

  1. @alejandrobernardis alejandrobernardis revised this gist Feb 10, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion handlers.py
    Original file line number Diff line number Diff line change
    @@ -19,5 +19,5 @@ def get(self, file_name):
    self.finish()
    return
    except:
    pass
    raise HTTPError(404)
    raise HTTPError(500)
  2. @alejandrobernardis alejandrobernardis revised this gist Feb 10, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion handlers.py
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ class AdminFileHandler(BaseHandler):

    @authenticated
    def get(self, file_name):
    _file_dir = os.path.abspath("")+"/mx/yr/app/status/downloads"
    _file_dir = os.path.abspath("")+"/my/path/downloads"
    _file_path = "%s/%s" % (_file_dir, file_name)
    if not file_name or not os.path.exists(_file_path):
    raise HTTPError(404)
  3. @alejandrobernardis alejandrobernardis created this gist Feb 10, 2012.
    23 changes: 23 additions & 0 deletions handlers.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    class AdminFileHandler(BaseHandler):

    @authenticated
    def get(self, file_name):
    _file_dir = os.path.abspath("")+"/mx/yr/app/status/downloads"
    _file_path = "%s/%s" % (_file_dir, file_name)
    if not file_name or not os.path.exists(_file_path):
    raise HTTPError(404)
    self.set_header('Content-Type', 'application/force-download')
    self.set_header('Content-Disposition', 'attachment; filename=%s' % file_name)
    with open(_file_path, "rb") as f:
    try:
    while True:
    _buffer = f.read(4096)
    if _buffer:
    self.write(_buffer)
    else:
    f.close()
    self.finish()
    return
    except:
    pass
    raise HTTPError(500)