上传图片到数据库 以BLOB形式 上传图像 @app.route('/api/upload', methods=['POST']) def save_text_and_image(): title = request.form.get('title', '') \# 获取标题 bodyText = request.form.get('bodyText', '') \# 获取正文文本 user = request.form.get('user', '') \# 获取用户信息 file = request.files.get('file') \# 获取上传的文件 \# 验证标题、正文文本和文件是否存在 if not title or not bodyText: return 'No text provided', 400 if not file or file.filename == '': return 'No file provided', 400 filename = secure_filename(file.filename) image_content = file.read() \# 使用 database_config 模块获取数据库连接 connection = get_db_connection() try: with connection.
如何能够通过http://8.130.89.73/avatars/logo.png访问图像
去找nginx的配置
首先是/etc/nginx/nginx.conf(总的配置) 或者/etc/nginx/conf.d/*.conf;(某个项目的配置) 其中会有这样的配置,他的意思是/images/ 路径被配置为直接从 /var/images/ 目录提供静态文件
\# 静态文件服务配置 location /images/ { alias /var/images/; autoindex off; \# 关闭目录列表 } 加上以下的代码就可以通过url访问图像了
\# 静态文件服务配置 location /avatars/ { alias /var/avatars/; autoindex off; \# 关闭目录列表 } 然后执行sudo nginx -s reload重新加载 Nginx 使配置生效
sudo nginx -s reload
Flask 快速入门指南 开启调试模式 flask --app hello run --debug 路由 使用 route() 装饰器把函数绑定到 URL。路由用于将请求的 URL 映射到具体的处理函数。
基本路由 @app.route('/') def index(): return 'Index Page' @app.route('/hello') def hello(): return 'Hello, World' 动态路由 动态变化 URL 的某些部分。
@app.route('/user/<username>') def show_user_profile(username): return f'User {escape(username)}' @app.route('/post/<int:post_id>') def show_post(post_id): return f'Post {post_id}' 唯一的 URL/重定向行为 @app.route('/projects/') def projects(): return 'The project page' @app.route('/about') def about(): return 'The about page' 使用 url_for 构建 URL @app.route('/hello') def hello(): return 'Hello, World' @app.
一、安装所需要的模块
~首先需要安装百度的aip模块(直接pip install baidu-aip会报错,需要镜像源,同时添加对镜像源的信任)
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn baidu-aip
安装完执行可能会遇到报错No module named 'chardet'
继续安装chardet:pip install chardet -i https://pypi.tuna.tsinghua.edu.cn/simple
参考的文档:
pip国内镜像源:https://zhuanlan.zhihu.com/p/623325525?utm_id=0&wd=&eqid=b13e6e180006c6dc0000000664816590
遇到报错Cannot determine archive format of xxx:https://blog.csdn.net/qq_43665602/article/details/126235981
二、在百度智能云创建应用
获取免费的测试资源(每月一千次)
创建的应用的AppID,API Key Secret Key等下用
三、车牌识别的代码
参考文档:https://developer.aliyun.com/article/1322015
from aip import AipOcr APP_ID = '自己的 App ID' API_KEY = '自己的 Api Key' SECRET_KEY = '自己的 Secret Key' # 创建客户端对象 client = AipOcr(APP_ID, API_KEY, SECRET_KEY) # 建立连接的超时时间,单位为毫秒 client.setConnectionTimeoutInMillis(5000) # 通过打开的连接传输数据的超时时间,单位为毫秒 client.setSocketTimeoutInMillis(5000) # 读取图片 def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.