• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Commons fileupload streaming api: FileItemIterator not being able to iterate twice

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
We are using the CFU streaming api to upload multiple image files. Our form has input text fields as well as input file fields. Before uploading the files we need to validate our text fields. This requires us to iterate over the FileItemIterator twice, once while validating to get the text field values and the second time to acutally get the file field values and save to disk. Our problem is that while trying to iterate the second time, the iter.hasNext() returns false even though we are trying to get the new iterator.
Below is our code:


The onBind code works fine. The onSubmit does not. Why is the FileItemIterator not being able to iterate in onSubmit even though we are obtaining a new iterator instance for the request??
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Iterating over the items reads (and exhausts) the InputStream, so you can't iterate twice. You'll need to rewrite the logic so that only a single iteration is necessary.
reply
    Bookmark Topic Watch Topic
  • New Topic