Skip to content

Single file upload option missing #472

@denlogv

Description

@denlogv

In the Label Studio UI, I can upload a single file, which, as far as I can tell, calls the task import endpoint api/projects/{project_id}/import with the file being specified in a multipart request. Currently, I don't see a way of doing this using the official SDK. I can achieve this by calling the internal client:

upload_response = ls._client_wrapper.httpx_client.request(
    f'api/projects/{project_id}/import',
    method='POST',
    files={'file': (uploaded_file_name, file_content, 'image/jpeg')},
    json=task,
    params={'return_task_ids': True}
)
task_id = str(upload_response['task_ids'][0])

However, this completely ignores the task dictionary, so it seems to be necessary to get the task id and then send another request to update the task with the task dictionary. However, it has some weird effects:

  1. annotations become just another generic field, so I don't see them in the UI.
  2. Uploaded file gets renamed internally by adding a prefix, but when I get its new name by the upload id:
file_upload_id = upload_response['file_upload_ids'][0]
new_filename = ls.files.get(file_upload_id).file
task['data']['image'] = f'/data/{new_filename}'
ls.tasks.update(task_id, data=task, project=project_id)

and then add it back to the task dictionary and update the task, the image file is not shown in the UI.

Is there a recommeded way to achieve the same UI functionality without having to register additional storages?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions