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?