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

481
Visualizações
Uploading a file via API in Playwright (Typescript)

What: Testing the upload of a file (image) via API using Playwright

In the API Docs, for the request it states:

REQUEST BODY SCHEMA:

multipart/form-data

file (string )

A file to upload. The file should follow the specifications of RFC 2388 (which defines file transfers for the multipart/form-data protocol).

My Code:

test("POST: Upload or Create a file", async ({ request, baseURL }) => {
    const response = await request.post(baseURL + "/v2/files", {
      headers: {
        Accept: "*/*",
        ContentType: "multipart/form-data",
        account: AccountID,
        Authorization: bearer,
      },
      multipart: {
        file: "../../lib/logo.png",
        purpose: "logo",
      },
    });

    const body = JSON.parse(await response.text());
    console.log("this is the status:" + body.status);
    expect(response.status()).toBe(201);

Instead of a 201 status, I receive a 400. Also in debug mode in VS Code, I see:

[ "file should not be null or undefined", ]

Which leads me to believe the file is not being sent or sent incorrectly.

I'm not sure how to structure the file key within multipart, thoughts?

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