-1

I'm trying to build a flask app where I can upload a JSON file. I followed the official flask tutorials; this is my code:

import os
from flask import Flask, flash, request, render_template, url_for
from flask_restful import Resource, Api
from flask_uploads import UploadSet, configure_uploads, DATA

app = Flask(__name__)

app.config['UPLOADED_FILES_DEST'] = os.getcwd()

file = UploadSet('SecretKey', DATA)

configure_uploads(app, file)

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

@app.route('/checkUpload', methods=['POST'])
def my_form_post():
    if request.method == 'POST' and 'file' in request.files:
    keyFile = file.save( request.files['keyfile'] )
# ...

My directory structure looks like this: folder - >

app.py

templates - > uploads.html

When I run the application , I get this error:

RuntimeError: no destination for set SecretKey

I understand that I need to set a destination to the file that's being uploaded, but I can't figure out how to properly do that; I can't understand why the way I'm currently setting the destination directory is wrong. Ideally, I don't want to store this file anywhere, I just want to take this file, check some credentials from it and then start a session if the credentials are valid. Any help is much appreciated. Thank you for your time in advance.

P.S: Please ignore the spacing of the code , and I've also looked into some other SO questions related to these:

1) Flask Upload Issue

2) Flask Upload Issue

but they didn't exactly had the same issue as I did, so I'm creating a new thread.

Danila Ganchar
  • 10,266
  • 13
  • 49
  • 75
Amith Adiraju
  • 306
  • 4
  • 18

1 Answers1

0

You didn't set destination to UploadSet. flask_uploads doesn't know where to store a files. Just set destination:

file = UploadSet('SecretKey', DATA, default_dest=lambda x: 'SecretKey')

Hope this helps.

Danila Ganchar
  • 10,266
  • 13
  • 49
  • 75