Пример #1
0
def upload(request):
    if request.method != "POST":
        return not_found()
    if "sessionid" not in request.args:
        return Response("You must submit a sessionid for your upload.")
    sessionid = request.args["sessionid"]

    filename = filehelper.get_filename(config.get_upload_path())
    session.set(sessionid, {"progress": 0, "upload_status": "uploading", "url": "", "filename": filename})
    request.environ["wsgi.input"] = StreamWrapper(
        request.environ["wsgi.input"], request.environ["CONTENT_LENGTH"], sessionid
    )
    # Save the file locally
    f = request.files["file"]
    path = config.get_upload_path() + filename
    f.save(path)
    f.close()

    filehelper.save_metadata(filename, {"title": f.filename, "description": ""})
    session.set(
        sessionid,
        {
            "progress": 100,
            "upload_status": "complete",
            "url": request.host_url + "file/" + filename,
            "filename": filename,
        },
    )
    return Response(
        "<!DOCTYPE html><html><head></head><body>\
                     <p>Upload OK</p></body>"
    )
Пример #2
0
 def _update_progress(self, bytes):
     self._read_bytes += bytes
     progress = int(float(self._read_bytes) / float(self._content_length) * 100)
     if progress > self._progress + 0.01:  # Only update progress if there is more than 1 % progress
         self._progress = progress
         params = {'progress': progress,
                 'upload_status': 'uploading',
                 'url': ''}
         session.set(self._sessionid, params)