[fileupload] Parse Multipart

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[fileupload] Parse Multipart

Philipp Höfler
Hi,

I am using the commons.fileupload library to parse a multipart request.
@POST
public void post(@Context HttpServletRequest request) throws Exception
{
    List<FileItem> multiParts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);

    for(FileItem part : multiParts)
    {
            System.out.printf("File %s, %s, %d%n", part.getName(),
                part.getContentType(), part.getSize());
    }
}


The method is part of a small osgi based app, that utilizes the HttpWhiteboard to implement a REST service.
The shown code is working.

Unfortunately, this is called by a quite old system, that does not provide a name field for each part.
The library ignores all parts, that does not have a name.

Is there any easy solution, how to avoid ignoring the unnamed parts?
Is it possible the set a random name if it does not exist?