2

I followed this tutorial but am unable to get a file to upload to the directory I want. It says it was succesful, but the file is not in the directory it's supposed to be.

Update I changed my views.py to try and fix the directory call but now I get this error:

File "/home/jsnyder10/Documents/45/app/views.py", line 33, in uploader f.save(os.path.join(app.config['UPLOAD_FOLDER']),secure_filename(f.filename)) IOError: [Errno 21] Is a directory: '/home/jsnyder10/Documents/45/uploads' 

views.py

@app.route('/mobility_import_html') @login_required def mobility_import_html(): return render_template('mobility_import_html.html') @app.route('/uploader', methods = ['GET', 'POST']) def uploader(): if request.method == 'POST': f = request.files['file'] #f.save(secure_filename(f.filename)) f.save(os.path.join(app.config['UPLOAD_FOLDER']),secure_filename(f.filename)) print("f.filename", f.filename) return 'success' 

mobility_import_html.html

{% extends "mobility.html" %} {% block mobility %} <form action ="{{ url_for('uploader') }}" method = "POST" enctype = "multipart/form-data"> <input type = "file" name = "file" /> <input type = "submit"/> </form> {% endblock %} 

init.py

import os from flask import Flask from flask.json import JSONEncoder from flask_sqlalchemy import SQLAlchemy from flask_login import LoginManager from flask_mail import Mail from flask_babel import Babel, lazy_gettext from config import basedir, ADMINS, MAIL_SERVER, MAIL_PORT, MAIL_USERNAME, \ MAIL_PASSWORD from .momentjs import momentjs app.config["UPLOAD_FOLDER"] = os.path.join(basedir, 'uploads') 
3
  • "It says" what says? Take a look at How to Ask Commented May 25, 2017 at 6:02
  • You should link to the tutorial, but I do not see opening file for saving. Commented May 25, 2017 at 6:02
  • Sorry about that, I must not have pasted the link properly. It is posted now. Commented May 25, 2017 at 7:44

1 Answer 1

1

Your save line should be something like:

f.save(os.path.join(app.config['UPLOAD_FOLDER'],secure_filename(f.filename)) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.