|
1 | 1 | import asyncio |
| 2 | +import copy |
2 | 3 | import datetime |
3 | 4 | import io |
4 | 5 | import json |
@@ -1373,52 +1374,39 @@ async def upload_annotations( |
1373 | 1374 | items_name_file_map: Dict[str, io.StringIO], |
1374 | 1375 | ) -> UploadAnnotationsResponse: |
1375 | 1376 | url = urljoin( |
1376 | | - self.assets_provider_url, |
1377 | | - f"{self.URL_UPLOAD_ANNOTATIONS}?{'&'.join(f'image_names[]={item_name}' for item_name in items_name_file_map.keys())}", |
| 1377 | + "self.assets_provider_url", |
| 1378 | + f"{self.URL_UPLOAD_ANNOTATIONS}?{'&'.join(f'image_names[]={item_name}' for item_name in items_name_file_map.keys())}", |
| 1379 | + ) |
| 1380 | + |
| 1381 | + headers = copy.copy(self.default_headers) |
| 1382 | + del headers["Content-Type"] |
| 1383 | + async with aiohttp.ClientSession( |
| 1384 | + headers=headers, |
| 1385 | + connector=aiohttp.TCPConnector(ssl=self._verify_ssl), |
| 1386 | + ) as session: |
| 1387 | + data = aiohttp.FormData() |
| 1388 | + |
| 1389 | + for key, file in items_name_file_map.items(): |
| 1390 | + file.seek(0) |
| 1391 | + data.add_field(key, bytes(file.read(), "ascii"), filename=key, content_type="application/json") |
| 1392 | + |
| 1393 | + _response = await session.post( |
| 1394 | + url, |
| 1395 | + params={ |
| 1396 | + "team_id": team_id, |
| 1397 | + "project_id": project_id, |
| 1398 | + "folder_id": folder_id, |
| 1399 | + "image_names": list(items_name_file_map.keys()), |
| 1400 | + }, |
| 1401 | + data=data |
1378 | 1402 | ) |
1379 | | - return self._request( |
1380 | | - url, |
1381 | | - "post", |
1382 | | - params={ |
1383 | | - "team_id": team_id, |
1384 | | - "project_id": project_id, |
1385 | | - "folder_id": folder_id, |
1386 | | - "image_names": list(items_name_file_map.keys()), |
1387 | | - }, |
1388 | | - files=[ |
1389 | | - (i[0], (*i, "application/json")) for i in items_name_file_map.items() |
1390 | | - ], |
1391 | | - content_type=UploadAnnotationsResponse, |
1392 | | - ) |
1393 | | - # async with aiohttp.ClientSession( |
1394 | | - # headers=self.default_headers, |
1395 | | - # connector=aiohttp.TCPConnector(ssl=self._verify_ssl), |
1396 | | - # ) as session: |
1397 | | - # data = aiohttp.FormData() |
1398 | | - # |
1399 | | - # for key, file in items_name_file_map.items(): |
1400 | | - # file.seek(0) |
1401 | | - # data.add_field(key, bytes(file.read(), "ascii"), filename=key, content_type="application/json") |
1402 | | - # # data.add_field(key, io.BytesIO(bytes("{}", "utf-8")), filename=key, content_type="application/json") |
1403 | | - # |
1404 | | - # _response = await session.post( |
1405 | | - # # url, |
1406 | | - # params={ |
1407 | | - # "team_id": team_id, |
1408 | | - # "project_id": project_id, |
1409 | | - # "folder_id": folder_id, |
1410 | | - # "image_names": list(items_name_file_map.keys()), |
1411 | | - # }, |
1412 | | - # data=data |
1413 | | - # ) |
1414 | | - # from pydantic import parse_obj_as |
1415 | | - # d = await _response.text() |
1416 | | - # data_json = await _response.json() |
1417 | | - # response = ServiceResponse() |
1418 | | - # response.status = _response.status |
1419 | | - # response._content = await _response.text() |
1420 | | - # response.data = parse_obj_as(UploadAnnotationsResponse, data_json) |
1421 | | - # return response |
| 1403 | + from pydantic import parse_obj_as |
| 1404 | + data_json = await _response.json() |
| 1405 | + response = ServiceResponse() |
| 1406 | + response.status = _response.status |
| 1407 | + response._content = await _response.text() |
| 1408 | + response.data = parse_obj_as(UploadAnnotationsResponse, data_json) |
| 1409 | + return response |
1422 | 1410 |
|
1423 | 1411 | async def upload_big_annotation( |
1424 | 1412 | self, |
@@ -1515,7 +1503,7 @@ async def upload_big_annotation( |
1515 | 1503 | return True |
1516 | 1504 | elif status.startswith("FAILED"): |
1517 | 1505 | return False |
1518 | | - time.sleep(1) |
| 1506 | + await asyncio.sleep(15) |
1519 | 1507 | else: |
1520 | 1508 | return False |
1521 | 1509 |
|
|
0 commit comments