mirror of
https://github.com/FAUSheppy/python-flask-picture-factory
synced 2025-12-06 07:01:37 +01:00
add redirect option after upload
This commit is contained in:
@@ -34,6 +34,8 @@ In addition to *encoding*, *scaleX* and *scaleY* you may also use the following
|
|||||||
# Uploading
|
# Uploading
|
||||||
This tool is not intended for uploading or large amounts of files, use SFTP/FTPS or whatever your server provides for. For pure convenience usage there is a */upload*/-location. It must be enabled by creating a file called *upload.enable* in the project root before the server is started.
|
This tool is not intended for uploading or large amounts of files, use SFTP/FTPS or whatever your server provides for. For pure convenience usage there is a */upload*/-location. It must be enabled by creating a file called *upload.enable* in the project root before the server is started.
|
||||||
|
|
||||||
|
For automatic redirection after upload you must have a reverse proxy setting a header *X-REAL-HOSTNAME* with the internet facing hostname of the server.
|
||||||
|
|
||||||
# With nginx as reverse-proxy
|
# With nginx as reverse-proxy
|
||||||
|
|
||||||
server {
|
server {
|
||||||
@@ -41,10 +43,12 @@ This tool is not intended for uploading or large amounts of files, use SFTP/FTPS
|
|||||||
location /{
|
location /{
|
||||||
proxy_pass http://localhost:5000;
|
proxy_pass http://localhost:5000;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /upload{
|
location /upload{
|
||||||
auth_basic "Auth Message";
|
auth_basic "Auth Message";
|
||||||
auth_basic_user_file "/path/to/auth/file";
|
auth_basic_user_file "/path/to/auth/file";
|
||||||
client_max_body_size 50m; # <-- important!
|
client_max_body_size 50m; # <-- important!
|
||||||
|
proxy_set_header X-REAL-HOSTNAME $host;
|
||||||
proxy_pass http://localhost:5000;
|
proxy_pass http://localhost:5000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,10 +136,15 @@ def upload():
|
|||||||
return ("Upload Disabled", 403)
|
return ("Upload Disabled", 403)
|
||||||
if flask.request.method == 'POST':
|
if flask.request.method == 'POST':
|
||||||
f = flask.request.files['file']
|
f = flask.request.files['file']
|
||||||
sfName = os.path.join(PICTURE_DIR, werkzeug.utils.secure_filename(f.filename))
|
fname = werkzeug.utils.secure_filename(f.filename)
|
||||||
|
sfName = os.path.join(PICTURE_DIR, fname)
|
||||||
if not os.path.isfile(sfName):
|
if not os.path.isfile(sfName):
|
||||||
f.save(sfName)
|
f.save(sfName)
|
||||||
return ('Success', 204)
|
realHostname = flask.request.headers.get("X-REAL-HOSTNAME")
|
||||||
|
if realHostname:
|
||||||
|
return flask.redirect(realHostname + "/media/" + fname)
|
||||||
|
else:
|
||||||
|
return ('Success', 204)
|
||||||
else:
|
else:
|
||||||
return ('Conflicting File', 409)
|
return ('Conflicting File', 409)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user