Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

295
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda