Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Juzar Roopawalla
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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??
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic