Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Files API upload does not accept BytesIO or in-memory bytes

Open
#459 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
api

Research direction

Start at the files_api.upload() implementation and trace how the file and options arguments are handled. Add focused coverage for raw bytes, BytesIO, Django InMemoryUploadedFile, and dict options, then verify uploads no longer require temporary files and the existing filename behavior remains intact.

Written by the indexing model from the issue text.

Description

Describe the bug

In hubspot-api-client version 12.0.0, the files_api.upload() method fails when passing a file from memory, such as a BytesIO object, bytes, or a Django InMemoryUploadedFile. The SDK attempts to call open() on the object, leading to errors like:

TypeError: expected str, bytes or os.PathLike object, not _io.BytesIO
UnicodeDecodeError: 'utf-8' codec can't decode byte ...
TypeError: a bytes-like object is required, not 'dict'

To Reproduce

from io import BytesIO
import json
file_bytes = b"test content"
response = client.files.files_api.upload(
    file=BytesIO(file_bytes),
    file_name="test.txt",
    folder_path="test",
    options=json.dumps{"access": "PUBLIC_NOT_INDEXABLE"}
)

Expected behavior

The SDK should accept file-like objects or raw bytes and upload them to HubSpot.
Users should not be forced to write temporary files to disk.

Actual behavior

The SDK treats the object as a filename string, attempts open(), and raises a TypeError or UnicodeDecodeError.

Suggested fix

Update files_api.upload() to properly detect file-like objects (bytes, BytesIO, Django UploadedFile) and avoid always calling open().
Ensure options can be passed as a dict and converted to JSON internally, rather than requiring json.dumps

Dominant language
Python
Stars
434
Forks
126
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from HubSpot/hubspot-api-python

All issues in HubSpot/hubspot-api-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.