Create Image Upload is broken for Sync and Async
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start with images.v1.create for both Cloudflare and AsyncCloudflare clients, then inspect tests/api_resources/images/test_v1.py around the linked coverage. Reproduce the multipart upload using the tuple shown for a WebP file and add coverage for the sync and async cases once the request accepts the upload without the form-field parsing error.
Written by the indexing model from the issue text.
Description
Confirm this is a Python library issue and not an underlying Cloudflare API issue.
- This is an issue with the Python library
Describe the bug
The Cloudflare Image Create function is broken.
There is an example below, this has also been discussed on StackOverflow
I cant see any test coverage for this use case.
To Reproduce
This is a working example using Python Requests
import requests
with open(
"water bottle.webp", "rb"
) as f:
data = f.read()
# try requests
files = {
"file": (
"water bottle.webp",
data,
"image/webp",
)
}
response = requests.post(
url=f"https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/images/v1",
headers={
"Authorization": f"Bearer ..."
},
files=files,
)
print(response.status_code)
print(response.json())
This is a broken example using the Cloudflare Sync function
with open(
"water bottle.webp", "rb"
) as f:
data = f.read()
from cloudflare import Cloudflare
client = Cloudflare(
api_token='...'
)
# Create a tuple: (filename, binary data, content type)
file_tuple = ("water bottle.webp", data, "image/webp",)
cloudflare_image = await client.images.v1.create(
account_id=CLOUDFLARE_ACCOUNT_ID,
file=file_tuple,
)
print(cloudflare_image)
The output is
cloudflare.BadRequestError: Error code: 400 - {'result': None, 'success': False, 'errors': [{'code': 5400, 'message': 'Bad request: Error parsing form fields'}], 'messages': []}
This is a broken example using the Async Cloudflare function
from cloudflare import AsyncCloudflare
client = AsyncCloudflare(
api_token='...'
)
# Create a tuple: (filename, binary data, content type)
file_tuple = ("water bottle.webp", data, "image/webp",)
cloudflare_image = await client.images.v1.create(
account_id=CLOUDFLARE_ACCOUNT_ID,
file=file_tuple,
)
print(cloudflare_image)
The output is
cloudflare.BadRequestError: Error code: 400 - {'result': None, 'success': False, 'errors': [{'code': 5400, 'message': 'Bad request: Error parsing form fields'}], 'messages': []}
Code snippets
OS
macOS
Python version
3.12.9
Library version
v4.1.0
- Dominant language
- Python
- Stars
- 509
- Forks
- 150
- Avg merge
- 3h 15m
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cloudflare/cloudflare-python
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
cloudflare/cloudflare-python#2747 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
cloudflare/cloudflare-python#2718 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
cloudflare/cloudflare-python#2692 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
cloudflare/cloudflare-python#2679 · 4 comments · 5 reactions ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
cloudflare/cloudflare-python#2745 · 1 comment ·
All issues in cloudflare/cloudflare-python
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
syfoud/Simulated_Scepter#172 ·
-
A cancelled tests run makes the coverage comment workflow fail and reports it as a red check on main Openarea: ci bug perceived difficulty: 3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Nitjsefnie-Harness-Commons/daedalus#921 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
EleutherAI/lm-evaluation-harness#4207 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ClickHouse/clickhouse-connect#1057 ·