My guess is that the application is run from a different location. What output do you get from this:
import os
print(os.getcwd())
It's for that directory you need to set permissions. Better yet, use an absolute path. Since the file is temporary, use tempfile
as detailed here.
foodforthought = request.form['txtfield']
with tempfile.NamedTemporaryFile() as fd:
fd.write(foodforthought)
fd.flush()
# Name of file is in the .name attribute.
s3.Bucket("bucketname").upload_file(Filename = fd.name, Key = usr+"-"+str(datetime.now()))
# The file is automatically deleted when closed, which is when the leaving the context manager.
Some final notes: You don't need to close
the file, since you use a context manager. Also, avoid setting 777 recursively. The safest way is to set +wX
in order to only set execute
bit on directories and write
bit on everything. Or better yet, be even more specific.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…