Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

293
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda