Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async def post_image_to_api(
- session: aiohttp.ClientSession,
- file_path: Path
- ) -> tuple[Path, str]:
- boundary = uuid.uuid4().hex
- headers = {
- "Content-Type": f"multipart/form-data; boundary={boundary}",
- }
- with open(file_path, "rb") as image_file:
- data = aiohttp.FormData()
- data.add_field("file", image_file, filename=file_path.name)
- await asyncio.sleep(60 / 100) # <- Задержка перед отправкой
- async with session.post("http://localhost:8000/images", data=data) as resp:
- json_response = await resp.json()
- return file_path, json_response["id"]
Advertisement
Add Comment
Please, Sign In to add comment