Bug: direct creator upload API call requires formdata instead of JSON

The API forces me to use content-type multipart/form-data for the images/v2/direct_upload endpoint instead of the expected application/json as documented in the API reference: api [DOT] Cloudflare [DOT] com/#cloudflare-images-create-authenticated-direct-upload-url-v2.

While requiring multipart/form-data for actual file uploads makes sense, the images/v2/direct_upload endpoint by design doesn’t accept files but is used exclusively to generate URLs for upload and should adhere to the general guidelines of the API documention.

I’m posting this here as paying Cloudflare Images customers have no way of opening support tickets.

Here a cURL reproduction:

curl --request POST \
 --url https://api.cloudflare.com/client/v4/accounts/MY_ACC_ID/images/v2/direct_upload \
 --header 'Authorization: Bearer MY_API_TOKEN' \
 --header 'Content-Type: application/json' \
 --data '{"metadata":{"myId":"dda801df-e266-44cf-9237-a7fe9d1f1337"}}'

ERROR 5415: Images must be uploaded as a form, not as raw image data. Please use multipart/form-data format

Same request but with form-data:

 curl --request POST \
 --url https://api.cloudflare.com/client/v4/accounts/MY_ACC_ID/images/v2/direct_upload \
 --header 'Authorization: Bearer MY_API_TOKEN' \
 --header 'Content-Type: multipart/form-data' \
 --form 'metadata={"myId":"dda801df-e266-44cf-9237-a7fe9d1f1337"}'

{
  "result": {
    "id": "MY_OBJECT_ID",
    "uploadURL": "https://upload.imagedelivery.net/MY_ACC_HASH/MY_OBJECT_ID"
  },
  "result_info": null,
  "success": true,
  "errors": [],
  "messages": []
}%

This topic was automatically closed after 15 days. New replies are no longer allowed.