Flask - uploadnotallowed error - when renaming a file to be saved
<p>I'm trying to upload an excel file in flask and give it a new name when saving, something like: <code>oldname.xlsx</code> to <code>newname.xlsx</code>.</p>

<p>Here is my code so far:</p>

<pre><code>from flask import Flask, render_template, send_file, request, redirect, url_for
from flask_uploads import UploadSet, configure_uploads, DOCUMENTS, IMAGES
from remove_characters import get_csv, edit_data, cleanup_data
import re
import os

app = Flask(__name__)

#the name 'datafiles' must match in app.config to DATAFILES
docs = UploadSet('datafiles', DOCUMENTS)
app.config['UPLOADED_DATAFILES_DEST'] = 'static/uploads'
configure_uploads(app, docs)
file_new_name = 'dataexcel'

@app.route("/upload", methods = ['GET', 'POST'])
def upload():
#user_file is the name value in input element
if request.method == 'POST' and 'user_file' in request.files:
    filestorage = request.files['user_file']
    path = "static/uploads/" + filestorage.filename
    filename = docs.save(filestorage, name = file_new_name)


    return redirect(url_for('results', path = path))


return render_template('upload.html')
</code></pre>

<p>So in the <code>save</code> function, I'm passing <code>file_new_name</code> to the name param, so it will be saved with that variable name.  I got the <code>name</code> param from flask upload docs, but I get an 'uploadnotallowed' error</p>

<p><a href="http://i.stack.imgur.com/u8Gtg.png" rel="nofollow"><img src="http://i.stack.imgur.com/u8Gtg.png" alt="enter image description here"></a></p>

<p>I'm wondering If I'm not following the right format for the <code>save</code> function, or my configurations are not set up properly.  I'm new to flask, so I'm still learning this cool web framework.  Thanks in advance</p>

<p>Ok, found my error.  The variable <code>file_new_name = 'dataexcel'</code> needs to have the extension, in this case the <code>.xlsx</code> ext. So the variable should be <code>file_new_name = 'dataexcel.xlsx'</code></p>

<p>the <code>save</code> function should look like this -> <code>filename = docs.save(filestorage, None, file_new_name)</code>.  <code>None</code> is the subfolder, if you want to pass a subfolder, just change it to something like <code>static/upload/dist</code>.</p>

python flask