Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working example for file upload #260

Open
anka opened this issue Jan 29, 2024 · 1 comment
Open

Working example for file upload #260

anka opened this issue Jan 29, 2024 · 1 comment

Comments

@anka
Copy link

anka commented Jan 29, 2024

Please provide a working example for the file upload using hubspot.files.files.api.files_api.FilesApi.

Using it like that

file_options = {
    "access": "PUBLIC_NOT_INDEXABLE"
}
response = FilesApi().upload(
    file_name=file_name,
    file=open('sample.txt', 'rb'),
    folder_path="/upload-folder",
    options=json.dumps(file_options),
)

results

Traceback (most recent call last):
  File "/my-project/development.py", line 25, in <module>
    r = Hubspot.upload_file(file_name="test.txt", content=f.read())
  File "/my-project/faabric_lib/hs.py", line 1577, in upload_file
    response = FilesApi().upload(
  File "/my-python/lib/python3.10/site-packages/hubspot/files/files/api/files_api.py", line 1418, in upload
    return self.upload_with_http_info(**kwargs)  # noqa: E501
  File "/my-python/lib/python3.10/site-packages/hubspot/files/files/api/files_api.py", line 1516, in upload_with_http_info
    return self.api_client.call_api(
  File "/my-python/lib/python3.10/site-packages/hubspot/files/files/api_client.py", line 378, in call_api
    return self.__call_api(
  File "/my-python/lib/python3.10/site-packages/hubspot/files/files/api_client.py", line 167, in __call_api
    post_params.extend(self.files_parameters(files))
  File "/my-python/lib/python3.10/site-packages/hubspot/files/files/api_client.py", line 481, in files_parameters
    with open(n, "rb") as f:
OSError: [Errno 63] File name too long: b'{\n  "version": "2.0",\n  ..... }\n}'

I am using hubspot-api-client==8.1.0.

@anka
Copy link
Author

anka commented Apr 26, 2024

Still the same problem in hubspot-api-client==9.0.0

The documentation for the upload method says:

:param file: File to be uploaded.
:type file: file

But in fact, it expects a file path as string instead of a file object. Passing a local file path, successfully uploads the file to the Hubspot File Manager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant