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

Filename should not be optional #758

Merged
merged 1 commit into from
Jan 17, 2024
Merged

Filename should not be optional #758

merged 1 commit into from
Jan 17, 2024

Conversation

gewenyu99
Copy link

@gewenyu99 gewenyu99 commented Jan 16, 2024

What does this PR do?

The file name is currently optional in our InputFile.from_bytes for Python.

This will give you an error 100% of the time because you can't infer a filename from bytes.

The error message will be something like:

/Users/wen/PycharmProjects/test-scripts/venv/bin/python /Users/wen/PycharmProjects/test-scripts/main.py 
/Users/wen/PycharmProjects/test-scripts/venv/lib/python3.9/site-packages/urllib3/__init__.py:34: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020
  warnings.warn(
Traceback (most recent call last):
  File "/Users/wen/PycharmProjects/test-scripts/venv/lib/python3.9/site-packages/appwrite/client.py", line 100, in call
    response.raise_for_status()
  File "/Users/wen/PycharmProjects/test-scripts/venv/lib/python3.9/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://cloud.appwrite.io/v1/storage/buckets/images/files

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/wen/PycharmProjects/test-scripts/main.py", line 46, in <module>
    main()
  File "/Users/wen/PycharmProjects/test-scripts/main.py", line 43, in main
    result = storage.create_file('images', ID.unique(), InputFile.from_bytes(byte_array, None, mime_type='image/jpeg'))
  File "/Users/wen/PycharmProjects/test-scripts/venv/lib/python3.9/site-packages/appwrite/services/storage.py", line 156, in create_file
    return self.client.chunked_upload(api_path, {
  File "/Users/wen/PycharmProjects/test-scripts/venv/lib/python3.9/site-packages/appwrite/client.py", line 142, in chunked_upload
    return self.call(
  File "/Users/wen/PycharmProjects/test-scripts/venv/lib/python3.9/site-packages/appwrite/client.py", line 112, in call
    raise AppwriteException(response.json()['message'], response.status_code, response.json().get('type'), response.json())
appwrite.exception.AppwriteException: Empty file passed to the endpoint.

Process finished with exit code 1

Test Plan

Manual testing.

If you try to use no filename:

TypeError: from_bytes() missing 1 required positional argument: 'filename'

Related PRs and Issues

(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)

Have you read the Contributing Guidelines on issues?

(Write your answer here.)

@abnegate abnegate changed the base branch from master to 1.5.x January 17, 2024 02:48
@abnegate abnegate changed the base branch from 1.5.x to master January 17, 2024 02:48
@abnegate abnegate merged commit 041f158 into master Jan 17, 2024
34 of 36 checks passed
@abnegate abnegate deleted the fix-python-inputfile branch January 17, 2024 02:49
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

Successfully merging this pull request may close these issues.

2 participants