tomgross/pcloud

cannot use folderid with uploadfile method

Closed this issue · 1 comments

In my script that uses pycloud I cannot use folderid=folderid, where folderid is an integer, with the uploadfile method. It causes some exceptions and doesn't upload the file.

My script has fileinfo = pc.uploadfile(files=[upload_file], folderid=folderid) and is causes exceptions (see below). I have to change the folderid=folderid to path='/' like below:

fileinfo = pc.uploadfile(files=[upload_file], path='/')

The pcloud api says that path is discouraged but still accepted. In lieu of path it provides a folderid parameter: https://docs.pcloud.com/methods/file/uploadfile.html

Exceptions when folderid is used with pycloud.uploadfile:

  File "/pcloud-upload/./pcloud-upload.py", line 215, in <module>
    fileinfo = pc.uploadfile(files=[upload_file], folderid=folderid)
  File "/home/alarm/.local/lib/python3.10/site-packages/pcloud/validate.py", line 19, in wrapper
    return func(*args, **kwargs)
  File "/home/alarm/.local/lib/python3.10/site-packages/pcloud/api.py", line 274, in uploadfile
    return self._upload("uploadfile", files, **kwargs)
  File "/home/alarm/.local/lib/python3.10/site-packages/pcloud/api.py", line 242, in _upload
    m = MultipartEncoder(fields=fields)
  File "/usr/lib/python3.10/site-packages/requests_toolbelt/multipart/encoder.py", line 125, in __init__
    self._prepare_parts()
  File "/usr/lib/python3.10/site-packages/requests_toolbelt/multipart/encoder.py", line 246, in _prepare_parts
    self.parts = [Part.from_field(f, enc) for f in self._iter_fields()]
  File "/usr/lib/python3.10/site-packages/requests_toolbelt/multipart/encoder.py", line 246, in <listcomp>
    self.parts = [Part.from_field(f, enc) for f in self._iter_fields()]
  File "/usr/lib/python3.10/site-packages/requests_toolbelt/multipart/encoder.py", line 494, in from_field
    body = coerce_data(field.data, encoding)
  File "/usr/lib/python3.10/site-packages/requests_toolbelt/multipart/encoder.py", line 472, in coerce_data
    return CustomBytesIO(data, encoding)
  File "/usr/lib/python3.10/site-packages/requests_toolbelt/multipart/encoder.py", line 535, in __init__
    buffer = encode_with(buffer, encoding)
  File "/usr/lib/python3.10/site-packages/requests_toolbelt/multipart/encoder.py", line 416, in encode_with
    return string.encode(encoding)
AttributeError: 'int' object has no attribute 'encode'

When I change folderid to using path then I get expected result, the file is uploaded.

Good catch @ikwyl6! Thanks.
The API call works, if you use folderid as string. But since the API documents it as int I added a fix here: 110c114