Hi,

I have a form as follows:
{{html}}
<form action="" enctype="multipart/form-data" method="post">
<input type="hidden" name="addFile" value="true" />
 <input type="file" id="myupload" name="newfile" />
 <input type=submit>
</form>
{{/html}}

And I'd like to perform a simple check that I can access the file (by returning 
the file size and a line-by-line echo) using a velocity script:
{{velocity}}
## If this page is called with addStudy=true then do something with the 
information
#if ($request.addFile == "true")
  {{info}}Request received to add file{{/info}}
  #set ($fileUpload = $xwiki.fileupload)
  #set ($newFileName = $fileUpload.getFileName("newfile"))
  #if (!$newFileName)
    {{warn}}Failed to find submitted file{{/warn}}
  #else
    Found file $newFileName to load
    #set ($discard = $fileUpload.loadFileList())
    #set ($fileitem = $fileUpload.getFileItems().get(0))
    Found file item for $fileitem.getFieldName() to load, of 
$fileitem.getSize() bytes
    #set ($filestream = $fileitem.getInputStream())
    {{info}}filestream.getText(){{/info}}
    $filestream.getText()
    {{info}}filestream.readLines(){{/info}}
    #foreach($line in $filestream.readLines())
    | $line
    #end
  #end
#end
{{/velocity}}

And also with a Groovy script:
{{groovy}}
if(request.addFile == "true") {
  println "{{info}}addFile requested {{/info}}"
  fileUpload = xwiki.fileupload
  newFileName = fileUpload.getFileName("newfile")
  if(newFileName != null) {
    println "Found file $newFileName to load"
    fileUpload.loadFileList()
    fileitem = fileUpload.getFileItems().get(0)
    println "Found file item for ${fileitem.getFieldName()} to load, of 
${fileitem.getSize()} bytes"
    filestream = fileitem.getInputStream()

    println "{{info}}filestream.getText(){{/info}}"
    println filestream.getText()

    println "{{info}}filestream.eachLine{{/info}}"
    filestream.eachLine {
      println "${it}"
    }
  } else {
     println "Failed to find submitted file"
  }
}
{{/groovy}}

I've tested this page out with a 3kb text file, and both scripts tell me I have 
a 4 byte file and I get no lines returned. I'm sure I'm being a total noob, but 
can somebody please put me out of my misery and explain why this isn't working?

_______________________________________________
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to