How to upload file with specified name?

Hello, When I try to set the name like this, I got an error
code:

     name = self.clean_file_name(video.name)
    video_file = self.client.files.upload(
                    file=Path(video.path),
                    config={"name": name},
                )

error:

/python3.12/site-packages/google/genai/files.py", line 704, in upload
    response=_File_from_mldev(self._api_client, return_file.json['file']),
                                                ~~~~~~~~~~~~~~~~^^^^^^^^
KeyError: 'file'

Without config it works, but with random name. I need to be able to retrieve files later via get(name=filename)

Hi @Oleksandr_Tsikhun , Could you try the following code to specify a custom filename?

uploaded_file = client.files.upload(
    file="path",
    config=types.UploadFileConfig(display_name='custom_name')
)

@GUNAND_MAYANGLAMBAM , thnx!You pushed me to solve my problem. To be able to get the file by name, I use your updated code:
config=types.UploadFileConfig(name='custom_name')
Appreciate!

but I still sometimes have this error… Could you explain why this error occurs?
I would be very grateful

Could you please share the detailed error message you encountered??

yes:
code:

                    file=Path(video.path),
                    config=UploadFileConfig(name=name)
                )

Error:


....

  File "...." line 197, in _upload_video

    video_file = self.client.files.upload(

                 ^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/sasha/.cache/pypoetry/virtualenvs/ai-room-analyser-G2aTKqgo-py3.12/lib/python3.12/site-packages/google/genai/files.py", line 704, in upload

    response=_File_from_mldev(self._api_client, return_file.json['file']),

                                                ~~~~~~~~~~~~~~~~^^^^^^^^

KeyError: 'file'

UPD: the same here - issues/913