I'm using Flask Uploads for an upload form in my Flask application. However, whenever I try to save a file I get this error:
File "/Users/Documents/virtual_environment/bin/../lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/app'
It seems like uploads doesn't have the necessary permissions to save files? Here's the configuration I'm using for flask-uploads:
UPLOADS_DEFAULT_URL = os.environ.get("UPLOADS_URL", "http://localhost:5000/")
UPLOADS_DEFAULT_DEST = "/app/uploads/"
UPLOAD_EXTENSIONS = set(["csv", "xls", "xsls"])
Also, here's how I save the actual file:
@app.route('/upload', methods = ['GET', 'POST'])
@app.route('/upload/', methods = ['GET', 'POST'])
@roles_accepted('admin', 'team')
def r_upload():
form = FileUploadForm()
if form.validate_on_submit():
filename = uploadSet.save(form.uploadfile.data)
url = uploadSet.url(filename)
flash("%s uploaded <a href=\'%s\'>HERE</a>!" % (filename, url))
return render_template('/uploads.html',
dashboard_title = "%s Uploads" % g.name,
form = form)
The error is caused by the save line. Any suggestions on how to fix this? Thanks.
Does your linux user have file permissions on /app/uploads/
? Check that using ls -la /app/uploads
.
Note that /app
would try to write files in the root of the filesystem at /
.
If you are looking to write files within your app, use app/uploads
instead of /app/uploads/
. From the error, it looks like /app
simply does not exist and writing to app/uploads
is precisely what you wanted to do.