Uploading Images via Django

I’m having trouble uploading an image via Django requests.post. whenever I send the request, I keep getting this error: {‘code’: ‘101’, ‘message’: ‘content-type is not supported’}

here’s my code

def generateImageUploadURL():
    headers = {"Content-Type":"application/json",
    "Authorization":"Bearer "+api_token}    
    reponse = requests.post("https://api.cloudflare.com/client/v4/accounts/"+cf_images_id+"/images/v1/direct_upload", headers=headers)
    response_data = json.loads(reponse.text)
    upload_url = response_data["result"]["uploadURL"]
    return upload_url

def uploadImage(file, url):
    headers = {"Content-Type":"application/json",
    "Authorization":"Bearer "+api_token}   
    files = {'file': file}
    reponse = requests.post(url, files=files, headers=headers)
    response_data = json.loads(reponse.text)
    image_url = response_data["result"]["variants"]
    return image_url

the file is sent to Django via the frontend. I’m stuck at this and have no idea how to fix this.

You aren’t sending a JSON request so you shouldn’t be sending the header for it. Remove the content-type header

I thought I needed it if I’m going to use requireSignedURLs. It works completely now. I really appreciate the help.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.