Closed quaid281 closed 1 year ago
Hi. Please use this code snippet for file uploads with the lower-level SDK API. There are some extra efforts needed to pass files via this API. Please also consider using higher level API, which makes this process much more simple.
That's not easy for me to read and understand. Is there another way, or is there an example of how to use this snippet with a image_path from a local directory?
Please check the documentation here.
If you need to pass other parameters than just files and image_quality
, consider this sample:
Is there another way
Use the high-level SDK API:
from cvat_sdk import make_client
from cvat_sdk.core.proxies.tasks import ResourceType
with make_client("localhost", credentials=("user", "password")) as client:
task = client.tasks.create_from_data(
spec={
"name": "task with local data",
"labels": [ { "name": "car" } ],
},
data_params={
"image_quality": 75,
},
resource_type=ResourceType.LOCAL,
resources=["image.jpg"],
)
@zhiltsov-max wow man ...that worked perfectly. Thank you so much for the example
I am trying to upload the images by creating a task in an already existing project inside an organization, but this does not work. I am able to create the task without any media but when i try to attach media with it, im unable to do so.
@alijawad07, do you receive any error? When working in an organization, please add client.organization_slug = "orgslug"
before creating the task.
I'm attempting to upload images to my task. Why would this code '''
Create a TasksApi instance
''' Give this error: File "C:\Users\AXW0J9E\Downloads\FPLAir\automaticProjectCreationv5.py", line 55, in create_cvat_task data_request = DataRequest(name=image_name,image_quality=75,chunk_size=0,image_data=file_bytes) File "C:\Users\AXW0J9E\AppData\Local\miniconda3\envs\qaqc\lib\site-packages\cvat_sdk\api_client\model_utils.py", line 1465, in attempt_convert_item raise get_type_error(input_value, path_to_item, valid_classes, cvat_sdk.api_client.exceptions.ApiTypeError: Invalid type for variable 'image_data'. Required value type is one of [NoneType, bool, date, datetime, dict, float, int, list, str] and passed type was bytes at ['image_data']
I'm lost on how I could fix this. I could not include in the file_bytes as a parameter in DataRequest and use this instead: ''' data_request = DataRequest(name=image_name,image_quality=75) tasks_api.create_data(id=task_id, data_request=data_request) ''' However, by using the code doesn't crash but no images are uploaded in CVAT.