[Flask] File Upload
Colin Haig
colin at techdata.net.au
Tue Nov 15 02:34:13 EST 2016
Hi Dmitry
I can upload smaller files – it is when the file is above 130k that the problem occurs.
def fnGetFileArea(cDestination):
cFileList = ''
if sys.platform == 'darwin':
cDestination = "/Volumes/documents"
session['platform'] = 'mac'
elif sys.platform == 'win32':
session['platform'] = 'win32'
cDestination = "p:\\"
return(cDestination)
@app.route('/docget',methods=['GET','POST'])
def docget():
cDocType = ''
cDestination = ''
aDocs = []
cFileList = []
srv = ''
if request.method == 'POST':
cDestination = fnGetFileArea(cDestination)
cUser = request.args.get('user')
cUserType = request.args.get('usertype')
cDocType = request.form['doctype']
session['user'] = cUser
if 'attach' in request.files:
file = request.files['attach']
filename = file.filename
if filename != '':
filename = filename.replace(' ','_')
if session['platform'] == 'mac':
cFileSaveArea = cUserType + '/' + cDocType
destination = '/'.join([cDestination+'/'+cFileSaveArea,filename])
cDestination = cDestination + '/' + cUserType
elif session['platform'] == 'win32':
cFileSaveArea = cUserType + '\\' + cDocType
destination = '\\'.join([cDestination+cFileSaveArea,filename])
cDestination = cDestination + '\\' + cUserType
try:
cError = file.save(destination)
except:
flash('could not save')
cFileList = os.listdir(cDestination)
return render_template('selectdoc.html',user=cUser,usertype=cUserType,aDocs=cFileList)
else:
cDestination = fnGetFileArea(cDestination)
if 'user' in request.args:
cUser = request.args.get('user')
session['user'] = cUser
if 'usertype' in request.args:
cUserType = request.args.get('usertype')
if session['platform'] == 'mac':
cDestination = cDestination + '/' + cUserType
if session['platform'] == 'win32':
cDestination = cDestination + '\\' + cUserType
cFileList = os.listdir(cDestination)
if cUser .strip() != '' and cUserType.strip() != '':
return render_template('selectdoc.html',user=cUser,usertype=cUserType,aDocs=cFileList)
Have tested on my windows apache server and small files are uploaded but large files fail.
Regards
Colin
From: Flask <flask-bounces+colin=techdata.net.au at python.org> on behalf of Dmitry <d at ddipp.net>
Date: Tuesday, 15 November 2016 at 2:48 pm
To: <flask at python.org>
Subject: Re: [Flask] File Upload
Check the write permissions on the folder in which you save the file.
When downloading a file passes 100% and then there is an error, then perhaps it is not connected with the limitation on size.
Or show code that allows to upload files to the server.
15.11.2016 11:33, Colin Haig пишет:
To All
I am trying to upload a file using flask – but when I upload a large file I get a server error.
I have tried the following :
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
When I reduce the above setting Flask reports a 413 error which is is supposed to do
Updated apache server
Have added LimitRequestBody 0 to my http.conf
If I upload the file though my locahost flask server there are no issues.
When I submit the file upload I can see a counter counting up to 100% but then it crashes with a server error – I have
checked the apache logs but can not see any error associated with the upload.
I have searched the web looking for answers but to no avail.
Any help greatly appreciated.
Regards
Colin
_______________________________________________
Flask mailing list
Flask at python.orghttps://mail.python.org/mailman/listinfo/flask
--
Dmitry Podkovyrkin
email: d at ddipp.net
_______________________________________________ Flask mailing list Flask at python.org https://mail.python.org/mailman/listinfo/flask
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20161115/45e4e542/attachment-0001.html>
More information about the Flask
mailing list