Hello, I am currently building an integration that downloads & uploads files from Box using the Box Python SDK.
I am having issues using the upload_stream
function (https://github.com/box/box-python-sdk/blob/main/docs/usage/files.md#upload-a-file
) with an IOBase stream.
I am doing the below (taken from the docs):
new_file = parent_folder.upload_stream(object_bytes, file_name)
The error I get it is:
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
File "upload_to_box", line 174, in upload_small_file
new_file = parent_folder.upload_stream(object_bytes, file_name)
File "/usr/local/lib/python3.10/site-packages/boxsdk/util/api_call_decorator.py", line 63, in call
return method(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/boxsdk/object/folder.py", line 322, in upload_stream
file_response = self._session.post(
File "/usr/local/lib/python3.10/site-packages/boxsdk/session/session.py", line 100, in post
return self.request('POST', url, **kwargs)
File "/usr/local/lib/python3.10/site-packages/boxsdk/session/session.py", line 138, in request
response = self._prepare_and_send_request(method, url, **kwargs)
File "/usr/local/lib/python3.10/site-packages/boxsdk/session/session.py", line 348, in _prepare_and_send_request
network_response = self._send_request(request, **kwargs)
I tried digging through the stack trace and beyond in the Python SDK code to see where a subtraction operand was occurring but couldn’t find it easily.
This same IOBase stream works fine with the chunked uploader system (https://github.com/box/box-python-sdk/blob/main/docs/usage/files.md#chunked-upload
) below:
upload_session: UploadSession = parent_folder.create_upload_session(file_size, file_name)
chunked_uploader = upload_session.get_chunked_uploader_for_stream(object_bytes, file_size)
new_file = chunked_uploader.start()
Exact line in Github for the stacktrace: https://github.com/box/box-python-sdk/blob/main/boxsdk/session/session.py#L348
Wondering if anyone has any inkling as to why/where this error is actually occurring. That could potentially help us debug on our side if there is something ultimately wrong with our IOBase stream.
For more context:
The object_bytes
IOBase stream was recently converted to be chunked to support a fully chunked system. Essentially we are trying to do chunked downloads from a 3rd part source resulting in our own IOBase that we use to chunk upload to Box when the file is >=20MB or do the in memory upload if it’s <20MB (as per the docs). It was working before when our object_bytes
IOBase stream was fully loaded into memory.