lwzm
8/2/2019 - 9:20 AM

file-share.py

gunicorn and pyinstaller and file-upload-app

upstream f {
    server 127.0.0.4:3000;
    keepalive 16;
}

server {
    server_name  f.*;
    root /home/xxxx;
    location / {
        proxy_buffering off;
        proxy_request_buffering off;
        if ($request_method = POST) {
            proxy_pass http://f;
        }
    }
}
#!/usr/bin/env python3

import shutil
from flask import Flask, Response, request

app = Flask(__name__)

@app.route('/<path:path>', methods=['GET', 'POST'])
def hello(path):
    if request.method == "POST":
        shutil.copyfileobj(request.stream, open(path, 'wb'), 4096)
        return '', 201
    return Response(open(path, 'rb'), mimetype="application/octet-stream")

application = app

if __name__ == '__main__':
    import bjoern
    bjoern.run(app, "127.0.0.4", 3000)
#!/usr/bin/env python3

import requests
from flask import Flask, escape, request, Response

app = Flask(__name__)

@app.route('/<path:path>', methods=['GET', 'POST'])
def hello(path):
    # todo: post patch put ...
    #       session
    rsp = requests.get('http://tyio.net/public/' + path, stream=True)
    return Response(rsp.raw, headers=dict(rsp.headers))


application = app