文件上传 Flask/ShinyProxy

Fileupload in Flask/ShinyProxy

在我的 Flask 应用程序中通过 form/POST 请求上传文件在直接执行应用程序时工作正常,但在 Shinyproxy 托管 Flask 应用程序时失败。我将问题追溯到 Shinyproxy 未正确执行表单 POST 请求的地步:

app.py:

from flask import Flask, request, render_template    
app = Flask(__name__, static_url_path="/static")

@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'GET':
        return render_template('index.html')
    else:
        return "POST request received"    
app.run(host='0.0.0.0', port=3838)

index.html:

<html>
<body>
    <form method=post enctype=multipart/form-data>
        <input type="file" name="file"/>
        <input type = "submit" value="Upload">  
    </form>  
</body>
</html>

returns,点击 "Upload" 后,GET 和 POST 请求是什么:

10.81.71.42 - - [23/Dec/2019 14:37:28] "GET / HTTP/1.1" 200 -
10.81.71.42 - - [23/Dec/2019 14:37:30] "POST / HTTP/1.1" 200 -

运行 通过

在 Shinyproxy 中完全相同的应用程序

Dockerfile

FROM python:3
RUN pip install flask werkzeug
RUN mkdir /templates
COPY ["index.html", "/templates"]
COPY app.py /
EXPOSE 3838
CMD ["python", "app.py"]

returns 相同但没有 POST 行:

172.17.0.1 - - [23/Dec/2019 14:39:42] "GET / HTTP/1.1" 200 -

shinyproxy.log 说

2019-12-23 14:42:33.682 DEBUG 17832 --- [XNIO-2 I/O-1] io.undertow.server.handlers.proxy        : Sent request ClientRequest{path='/', method=POST, protocol=HTTP/1.1} to target 10.81.71.42 for exchange HttpServerExchange{ POST /proxy_endp
oint/b933863e-9fad-4d00-a657-034ede313e34/ request {Accept=[text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9], Accept-Language=[de-DE,de;q=0.9,en-US;q=0.8,en;q=0.
7], Cache-Control=[max-age=0], Accept-Encoding=[gzip, deflate], Origin=[http://192.168.76.81:8080], User-Agent=[Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36], Connectio
n=[keep-alive], Content-Length=[188], Content-Type=[multipart/form-data; boundary=----WebKitFormBoundarymPv6WtCTpGZQqRbF], Cookie=[JSESSIONID=CZxjGBM7BW597wysbBABgNWZL2x7qvsfujWVERgR], Referer=[http://192.168.76.81:8080/app_direct/flask_t
est/], Upgrade-Insecure-Requests=[1], Host=[192.168.76.81:8080]} response {Expires=[0], Cache-Control=[no-cache, no-store, max-age=0, must-revalidate], X-XSS-Protection=[1; mode=block], X-Content-Type-Options=[nosniff], Pragma=[no-cache]}
}                                                                                                                                                                                                                                             
2019-12-23 14:42:33.683 DEBUG 17832 --- [XNIO-2 I/O-1] io.undertow.request.io                   : Fixed length stream closed with with 188 bytes remaining                                                                                    
2019-12-23 14:42:33.683 DEBUG 17832 --- [XNIO-2 I/O-1] i.u.client.http.HttpClientExchange       : request terminated for request to localhost/127.0.0.1:20000 /                                                                               
2019-12-23 14:42:33.683 ERROR 17832 --- [XNIO-2 I/O-1] io.undertow.proxy                        : UT005028: Proxy request to /proxy_endpoint/b933863e-9fad-4d00-a657-034ede313e34/ failed                                                     

io.undertow.server.TruncatedResponseException: null                                             

有人知道如何在 shinyproxy(或其他方式)中托管此应用程序吗?我想让并发用户上传文件而不用同一个dockercontainer/not互相干扰

谢谢和亲切的问候,

shosaco

这是 Shinyproxy 2.2.0 和 2.3.0 中的错误。恢复到 ShinyProxy 2.1.0 可以解决问题,请参阅 https://github.com/openanalytics/shinyproxy/issues/184