|
@@ -8,19 +8,22 @@ from infer import DoorInference
|
|
|
from logger import logger
|
|
|
|
|
|
async def upload_image(session, url, payload, files):
|
|
|
- form_data = aiohttp.FormData()
|
|
|
- # 添加普通表单数据
|
|
|
- for key, value in payload.items():
|
|
|
- form_data.add_field(key, value)
|
|
|
+ try:
|
|
|
+ form_data = aiohttp.FormData()
|
|
|
+ # 添加普通表单数据
|
|
|
+ for key, value in payload.items():
|
|
|
+ form_data.add_field(key, value)
|
|
|
|
|
|
- # 添加文件数据
|
|
|
- for key, (filename, content, content_type) in files:
|
|
|
- form_data.add_field(key, content, filename=filename, content_type=content_type)
|
|
|
-
|
|
|
- # 发起 POST 请求
|
|
|
- async with session.post(url, data=form_data) as response:
|
|
|
- result = await response.text()
|
|
|
- logger.info(result)
|
|
|
+ # 添加文件数据
|
|
|
+ for filename, content, content_type in files:
|
|
|
+ form_data.add_field("file", content, filename=filename, content_type=content_type)
|
|
|
+
|
|
|
+ # 发起 POST 请求
|
|
|
+ async with session.post(url, data=form_data) as response:
|
|
|
+ result = await response.text()
|
|
|
+ logger.info(result)
|
|
|
+ except Exception as error:
|
|
|
+ logger.error(f'Error: {str(error)}')
|
|
|
|
|
|
async def process_stream():
|
|
|
logger.info("====== Start Server =======")
|
|
@@ -72,8 +75,8 @@ async def process_stream():
|
|
|
}
|
|
|
|
|
|
files = [
|
|
|
- ('file', (filename, content, 'image/jpeg')),
|
|
|
- ('oldFile', (filenameori, contentori, 'image/jpeg'))
|
|
|
+ (filename, content, 'image/jpeg'),
|
|
|
+ (filenameori, contentori, 'image/jpeg')
|
|
|
]
|
|
|
|
|
|
# 使用协程上传图像
|