1

So, I'm trying to make a flask mini-app that has an upload button which will upload images and then save that image in another folder named "upimgs". We need to do some image processing operation on the uploaded image later using google cloud vision api. The code is :

app = Flask(__name__)
@app.route('/')
def upload_file():
    return '''<html><h1>Upload a file</h1>
            <body><form action = "http://35.231.238.112:8085/upload" method = "POST" enctype = "multipart/form-data">
            <input type="file" name="file"/><input type="submit"/>
            </form>
            </body></html> '''

@app.route('/upload',methods=["GET","POST"])
def upload_lnk():
    if request.method == 'POST':
            f = request.files['file']
            f.save(os.path.join(app.config['/upimgs/'], filename))
            cmd2 = "python pj2new.py upmigs/" + f.filename
            cmd2 = str(cmd2)
            #some more code to run that output in flask browser

However it shows the following error :

KeyError: '/upimgs/'

Where is the probable error? I looked up to this : Refering to a directory in a Flask app doesn't work unless the path is absolute However the problem is not similar. I'm facing issue with uploading images in the server whether that one have file path issue.

Arkistarvh Kltzuonstev
  • 6,824
  • 7
  • 26
  • 56

1 Answers1

0

add this line with your images directory

app.config['upimgs'] = "/home/user/app/folder"

Official Docs

tomasantunes
  • 814
  • 2
  • 11
  • 23