I'm trying to upload a file with Flask and write a renamed file at completion. Per the Flask-Uploads docs, save() has a name parameter for this purpose. I receive TypeError: save() got an unexpected keyword argument 'name' when using the code below. If I omit the name portion of the save function, file.save(os.path.join('/path/to/uploads', filename)), everything works as intended.
My intent is to prepend the cust value from the wtform that the filefield is located at as the filename that is written, custvalue_filename.extension, as evidenced by my attempt with name=renfn.
views.py
def fc_upload():
form = InvFcUploadForm(next=request.args.get('next'))
if request.method == 'POST' and form.validate_on_submit():
file = request.files['file']
if file:
filename = secure_filename(file.filename)
renfn = str(form.cust.data) + '_' + filename + '.'
file.save(os.path.join('/path/to/uploads',
filename), name=renfn)
flash('File uploaded.', 'success')
return render_template('inventory/fc_upload.html', form=form)
I'm just learning python and Flask, so I fully suspect I'm missing something obvious. Thank you in advance.