Answer the question
In order to leave comments, you need to log in
Why is it possible to save the image? flask?
I'm trying to save the uploaded image like this: file.save(secure_filename(file.filename)) saving itself works, the picture appears, but if I add the return detect_faces_in_image(file) line below (result output), then the following error appears: builtins.OSError OSError: cannot identify image file how can i fix this?
ps the image is needed to add text to it and display it, maybe there is another way to do this?
@app.route('/', methods=['GET', 'POST'])
def upload_image():
# Check if a valid image file was uploaded
if request.method == 'POST':
if 'file' not in request.files:
return redirect(request.url)
file = request.files['file']
if file.filename == '':
return redirect(request.url)
if file and allowed_file(file.filename):
file.save(secure_filename(file.filename)) // сохранение изображения
# The image file seems valid! Detect faces and return the result.
return detect_faces_in_image(file)
# If no valid image file was uploaded, show the file upload form:
return '''
<!doctype html>
<title>text</title>
<h1>text</h1>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="Upload">
</form>
'''
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question