Issue
I am attempting to setup a REST API on a Wildfly App Server that accepts file uploads. While testing it I came across the following issue. When attempting to upload using Content-Type: multipart/form-data
I am receiving the following response:
HTTP Status Code: 400
Content-Type: text/html;charset=UTF-8
Body: "java.io.IOException: RESTEASY007550: Unable to get boundary for multipart"
This is the attempted request.
Headers
{
"content-length": "233",
"content-type": "multipart/form-data",
"accept-encoding": "multipart/form-data",
"authorization": "Bearer ommitted"
"user-agent": "PostmanRuntime/7.28.3"
}
Body
----------------------------976685076323434093219932
Content-Disposition: form-data; name="file"; filename="import.csv"
Content-Type: text/csv
destination
1234567890
----------------------------976685076323434093219932--
The API endpoint is configured as following:
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
@Stateless
@Path("/import")
@Produces(MediaType.APPLICATION_JSON)
public class ImportAPI {
@POST
@Path("/{id}/do")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response doImport(
@Context HttpServletRequest request,
@PathParam("id") Integer campaignId,
MultipartFormDataInput input) {
// Code omitted
return Response.ok().build();
}
}
There is no error log printed on server log when the error occurs. I am using Wildfly 23 and RESTEasy 3.15.1.Final (provided by Wildfly App Server).
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
<version>3.15.1.Final</version>
<scope>provided</scope>
</dependency>
I am not entirely sure if it's something wrong in the request or in the API endpoint and I am looking to shed some light on it.
Solution
The Content-Type
field is wrong. In your example it needs to be something like:
"Content-Type": multipart/form-data; boundary="--------------------------976685076323434093219932"
There are two fewer minus (dash) characters than are shown in the current body of your example.
Answered By - stdunbar