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

480
Views
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
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!