I have this create function using Boto within the Flask and it has been working for months perfectly, but suddenly it just stopped working, and I can’t seem to figure out why.
@posts_blueprint.route('/create_post', methods=['POST'])
def create_post():
if request.files["image"]:
file = request.files['image']
folder_path = os.environ.get('S3_FOLDER')
file_save = folder_path + file.filename
print(file.filename)
try:
client.upload_fileobj(file, 'pythonpat', file_save)
make_file_public('pythonpat', file_save)
except Exception as e:
print(f"Error uploading file: {e}")
post = Post(title=request.form['title'], body=request.form['body'],
author=request.form['author'], image=file_save, slug=slugify(request.form['title']))
uploaded_tags = request.form['tags']
saved_tags = uploaded_tags.split(',')
for tag_name in saved_tags:
tag_name = tag_name.strip()
tag = Tag.query.filter_by(name=tag_name).first()
if not tag:
tag = Tag(name=tag_name)
post.tags.append(tag)
db.session.add(post)
db.session.commit()
return jsonify({
'status': 200,
'message': 'Post uploaded successfully'
}), 200
return jsonify({
'status': 400,
'message': 'Image not attached'
}), 200
and my error:
Error uploading file: An error occurred (InvalidArgument) when calling the PutObject operation: None