Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
560 views
in Technique[技术] by (71.8m points)

java - How multipart form data upload handles large file

I am using quarkus framework for java application.I have created 2 rest apis for consuming file data.

    @POST
    @Path("file")
    @Consumes(MediaType.APPLICATION_OCTET_STREAM)
    @Produces(MediaType.APPLICATION_JSON)
    public Response uploadFile(byte[] fileData) {
        System.out.println("Received file of size = " + fileData.length);
        String s = new String(fileData);
       return Response.ok().build();
    }

    @POST
    @Path("files")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Produces(MediaType.APPLICATION_JSON)
    public void uploadFile(@MultipartForm FormData fileData) throws IOException {
        System.out.println("Received file of size = ");
        System.out.println(fileData.file.length());
        return Response.ok().build();
    }

FormData class looks like this

public class FormData {

    @FormParam("file")
    @PartType(MediaType.APPLICATION_OCTET_STREAM)
    public File file;
}

While both of these rest endpoint works fine for small files. But if i upload file as big as 700MB first endpoint fails with OOM issue while file upload with multipart-form succeed. Can someone explain how memory is managed in case of multipart-form upload?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...