Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

294
Views
How to post binary in Python for Strapi API

For Strapi, I am given this JavaScript boilerplate to upload a file from a form. For more information see here: https://docs.strapi.io/developer-docs/latest/plugins/upload.html#upload-files-related-to-an-entry

  const formElement = document.querySelector('form');

  formElement.addEventListener('submit', (e) => {
    e.preventDefault();

    const request = new XMLHttpRequest();
    request.open('POST', '/upload');
    request.send(new FormData(formElement));
  });

I am writing a Python program. How do I translate this in Python?. I am not using a form, I am pulling the file from a location on the drive.

But there is a warning in the documentation: You have to send FormData in your request body.

This is what I have so far:

url = f"{strapi_server_url}/api/upload"

headers = {
    'Authorization': f"Bearer {jwt}",
}
file=open(os.getcwd() + f'\\toys\\{filename}', 'rb')
data = file.read()
print(f"LENGTH FILE: {len(data)}")
response = requests.post(url,files={'file': data}, headers=headers)

I get a 400 error. 'ValidationError': 'Files are empty'. But I verified the length of the 'data' variable: 5 MB.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!