HumanSignal / label-studio

Label Studio is a multi-type data labeling and annotation tool with standardized output format
https://labelstud.io
Apache License 2.0
19.29k stars 2.4k forks source link

Upload multiple direct files via API #4484

Open Raven888888 opened 1 year ago

Raven888888 commented 1 year ago

Describe the bug For a single direct file upload to a project, it is working perfectly fine. However, when I upload multiple direct files to the same project, it does not support it.

To Reproduce

  1. Create a project with template more than 1 data keys

    <View>
    <Header value="Please review the depth map on the image" />
    <View style="display: flex;">
    <View style="width: 100%;">
      <Image name="img-left" value="$image1"/>
    </View>
    <View style="width: 100%;">
      <Image name="img-mid" value="$image2"/>
    </View>
    <View style="width: 100%;">
      <Image name="img-right" value="$image3"/>
    </View>
    </View>
    <View>
    <Header value="Test"/>
    <Choices name="comparison" toName="img-left" showInline="true">
      <Choice value="Yes"/>
      <Choice value="No"/>
    </Choices>
    </View>
    </View>
  2. Use API to upload direct files

    files = {
    'media': open(filename, 'rb')
    }
    requests.post(self.ls_url + 'api/projects/' + project_id + '/import?commit_to_project=false', files=files, headers={'Authorization': 'Token ' + self.token})
  3. Hit error

    {
    "id": "5ca95a39-4909-48a5-b368-54ee24b37241",
    "status_code": 400,
    "version": "1.8.0",
    "detail": "Validation error",
    "exc_info": null,
    "validation_errors": {
        "non_field_errors": [
            "Failed to parse input file upload/1906/fb0ecb39-cam_depthmap_189.png: [ErrorDetail(string='Your label config has more than one data key and direct file upload supports only one data key. To import data with multiple data keys, use a JSON or CSV file.', code='invalid')]"
        ]
    }
    }
  4. I also try doing this, but also fail

    files = {
    'media': open(filename, 'rb'),
    'media2': open(filename2, 'rb'),
    'media3': open(filename3, 'rb')
    }
    requests.post(self.ls_url + 'api/projects/' + project_id + '/import?commit_to_project=false', files=files, headers={'Authorization': 'Token ' + self.token})

Expected behavior Able to do multiple direct files upload via API.

Environment (please complete the following information):

KwanKwan22 commented 1 year ago

I'm currently facing a similar issue as well.

hogepodge commented 1 year ago

What error does the second request fail with? The first error gives the reason why the upload fails (you have multiple images associated with the labeling configuration, and direct file upload of multiple files is not supported).

KwanKwan22 commented 1 year ago

This is the input that I did, I'm assuming having 3 the same image wouldn't introduce any error. files = { 'media' = open(data_to_upload, 'rb'), 'media2' = open(data_to_upload, 'rb'), 'media3' = open(data_to_upload, 'rb') }

This is the output message that I got {"id":"7f906c60-29e4-461b-80ad-2b64d60dd4d8","status_code":400,"version":"1.8.0","detail":"Validation error","exc_info":null,"validation_errors":{"non_field_errors":["Failed to parse input file upload/1957/8e172e30-merged_image.png: [ErrorDetail(string='Your label config has more than one data key and direct file upload supports only one data key. To import data with multiple data keys, use a JSON or CSV file.', code='invalid')]"]}}

bieli commented 1 year ago

I have a similar message when I deploy the tool from official instructions in venv + run from the terminal console. When I try to import PNG files (in the "Import Data" view), I can see a message like this:

[bc73a464-263a-4dc2-b822-fe3d96ebd1cd] Validation error (Failed to parse input file upload/1/3f76192b-myimage.png: [ErrorDetail(string='Your label config has more than one data key and direct file upload supports only one data key. To import data with multiple data keys, use a JSON or CSV file.', code='invalid')])

Maybe I missed something in UI, but I can see instructions in "Import Data" that I can import PNG files. I've synced local catalogs in the "Cloud Storage" tab with success.

Please give me tips, on how to go forward with this tool.