Test API upload file using Playwright when having both multipart and formdata

Playwright request currently does not support having both multipart and formdata. It only supports one type of multipart, formdata, or data alone. So how do we pass the form data along with multipart.

Donald Le
2 min readFeb 23, 2023
Photo by Austvika

Take this upload file with Postman as an example:

In this API upload file, we’re having form-data with forms for “file”, “data_type”, “gr”. When making API request with Playwright, we must include this form along with mimeType like this:

await request.post(`/api/core/projects/${projectId}/studies`,{
headers:{
'Authorization':`Bearer ${accessToken}`,
'ContentType':'multipart/form-data'
},
multipart:{
file: {
name:file,
mimeType:"application/octet-stream",
buffer: jsonFile,
},
},
form:{
data_type:dataType,
group_study_by_folder:groupStudyByFolder…

--

--

Donald Le

A passionate automation engineer who strongly believes in “A man can do anything he wants if he puts in the work”.