首页 > 解决方案 > HTML 和 Flask POST 图像上传停止工作

问题描述

我的烧瓶/html POST 图像上传系统过去一直有效,但现在我看到图像没有上传到它应该上传到的文件夹。我在运行服务器时收到的错误消息是针对图像的压缩并显示“Nonetype has no attribute shape”,这是由于我认为是图像无法上传造成的。正如我在标题中所说,这段代码过去一直有效,有时当代码没有刷新服务器时会修复错误。HTML 代码:

<html>
<head>
    <link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='style.css') }}">
    <title>Upload</title>
</head>
<body>
<form method=POST id="submitbox" enctype=multipart/form-data action="{{ url_for('upload') }}">
    <input type=file name=photo>
    <input type="submit" id="submittext">
</form>
</body>
</html>

蟒蛇代码:

if request.method == 'POST' and 'photo' in request.files:
            global file_name
            file_name = photos.save(request.files['photo'])
            print(file_name)
            global file_path
            file_path = os.path.join(r'FILEPATH', file_name)
            print(file_path)
            img = cv2.imread(file_path)
            height, width, _ = img.shape
            roi = img[0: height, 0: width]
            _, compressedimage = cv2.imencode(".jpg", roi, [1, 90]

提前感谢您的帮助!

第 304 行,在上传高度、宽度、_ = img.shape AttributeError: 'NoneType' object has no attribute 'shape'

标签: pythonhtmlopencvflaskpost

解决方案


推荐阅读