Skip to content

FileClient.upload_file() fails with <400 Bad Request> when including metadata. #206

@ktvanzwol

Description

@ktvanzwol

Including custom metadata when uploading a file using the FileClient.upload_file() results in a 400 Bad Request response.

Example:

    metadata = {
        "custom_name": "data.bin",
        "description": "This is a test file.",
    }

    try:
        http_config = JupyterHttpConfiguration()
        file_client = FileClient(http_config)
        with open("data.bin", "rb") as file:
            file_client.upload_file(
                file=file,
                metadata=metadata,
            )
    except Exception as e:
        print(f"Error uploading file: {e}")

Output:

Error uploading file: Server responded with <400 Bad Request> (https://test-api.lifecyclesolutions.ni.com/nifile/v1/service-groups/Default/upload-files).

name='SkylineWebServices.ErrorParsingRequest' code=-252216 message='The metadata field was specified as a file.' args=[] resource_type=None resource_id=None inner_errors=[]

Using requests directly or testing the endpoint directly from the Swagger page does work correctly when including metadate. based on the server error upload_file seems to include metadata as a file upload instead of a plain form field.

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