FileUpload MultipartContent get all FormFields first
Im trying to upload file with several post parameters
I need to get all form fields fist as I need those to name file, to decide
where to save file etc
This is what I have right now.
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(new File(tempPath));
ServletFileUpload upload = new ServletFileUpload(factory);
try{
List<?> fileItems = upload.parseRequest(request);
Iterator<?> i = fileItems.iterator();
System.out.println("Iterating through upload request");
while ( i.hasNext () )
{
FileItem fi = (FileItem)i.next();
if (fi.isFormField ())
{
// get field values
}else {
// process files
}
}
}catch(Exception ex) {
System.out.println( ex.getMessage());
}
Is it possible to ok to iterate through the request for a second time so
that in first iteration it can handle Formfields and in the next
iteration, Filefield also
Like below
while ( i.hasNext () )
{
FileItem fi = (FileItem)i.next();
if (fi.isFormField ())
{
// get field values
}
}
while ( i.hasNext () )
{
FileItem fi = (FileItem)i.next();
if (!fi.isFormField ())
{
// parse files
}
}
How this could be possible. Please help
No comments:
Post a Comment