在python3中使用flask同时上传多个文件

时间:2019-09-11 13:15:19

标签: python flask

我正在尝试在python3中制作Web应用程序。为此,我正在使用以下代码上传文件并将其保存在文件夹中:

app = Flask(__name__)
Bootstrap(app)
db = SQLAlchemy(app)

# Configuration for File Uploads
files = UploadSet('files',ALL)
app.config['UPLOADED_FILES_DEST'] = 'static/uploadsDB'
configure_uploads(app,files)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///static/uploadsDB/filestorage.db'

# Saving Data To Database Storage
class FileContents(db.Model):
    id = db.Column(db.Integer,primary_key=True)
    name = db.Column(db.String(300))
    modeldata = db.Column(db.String(300))
    data = db.Column(db.LargeBinary)


@app.route('/')
def index():
    return render_template('index.html')


@app.route('/dataupload',methods=['GET','POST'])
def dataupload():
    if request.method == 'POST' and 'csv_data' in request.files:
        file = request.files['csv_data']
        filename = secure_filename(file.filename)
        file.save(os.path.join('static/uploadsDB',filename))
        fullfile = os.path.join('static/uploadsDB',filename)

但是问题是我不能同时上载所有文件,并且每次必须返回上一页并上载下一个文件时,这都会造成问题。如何解决此问题,以便能够一起上传所有文件?

0 个答案:

没有答案