Skip to content

Cannot upload an image using API with python #5239

@ammar3010

Description

@ammar3010

Hey, I am working on a project where I need to upload images to pocketbase database. Database schema is like this:

timestamp: DateTime
img: File
processed: Boolean

I am using this approach to upload the image:

with open("img.jpeg", "rb") as file:
    encoded_string = base64.b64encode(file.read()).decode("utf-8")
    
    url = "https://pbdev1.s1.ixon.cc/api/collections/hawknest_raw/records"
    
    headers = {
        "Content-Type": "application/json", 
        "Authorization": f"{API_KEY}"
    }
    
    data = {
        "timestamp": "", 
        "img": encoded_string, 
        "processed": False
    }
    
    response = requests.post(url, headers=headers, data=json.dumps(data))
    print(response)
    

It is giving 400 response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions