Back

getFileDownload, getFileView returning bytes in python sdk?

  • 0
  • Storage
ZachHandley
12 Jan, 2024, 02:32

yeah so I'm getting bytes back from the get_file_view, and get_file_download, I thought I would get back a URL as with the desktop client?

TL;DR
Developers are experiencing an issue with the `getFileDownload` and `getFileView` endpoints in the Python SDK. They are receiving bytes instead of a URL when using these endpoints. They are unsure if this is the intended behavior for the server SDK. They have also tried converting the bytes to a string but have been unsuccessful. The error message they received when attempting to convert the bytes is included. They are wondering if this issue is normal or if it is a bug. Solution: The cause of the issue is unclear. It is suggested to reach out to <@462046107556511744> for further clarification and assistance.
ZachHandley
12 Jan, 2024, 02:35
TypeScript
image_document = self.database.add_user_image(
                    image_request.image,
                    f"{image_request.userId}_{datetime.now().timestamp()}{file_extension}",
                    image_request.mimetype,
                    image_request.userId,
                )
                print(f"Uploaded image document ID: {image_document.get('$id')}")  # type: ignore
                file_url = self.database.storage.get_file_view(
                    image_request.userId,
                    image_document.get("$id"),  # type: ignore
                )
                print(f"File: {json.dumps(file_url, indent=4)}")

I've gotten back (from each endpoint) bytes and Idk why, so

TypeScript
print(f"File: {json.dumps(file_url, indent=4)}")
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.7/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
          ^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.7/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/encoder.py", line 202, in encode
    chunks = list(chunks)
             ^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.7/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/encoder.py", line 439, in _iterencode
    o = _default(o)
        ^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.7/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type bytes is not JSON serializable
ZachHandley
12 Jan, 2024, 02:59

@Drake is this supposed to happen?

ZachHandley
12 Jan, 2024, 02:59

Or is the server SDK not meant to be used like this

ZachHandley
12 Jan, 2024, 02:59

cause I can't convert it to a string either

Drake
12 Jan, 2024, 02:59

Only the web sdk gives a URL

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more