0

I have an upload action that receives a file from a form on a view. Validation is done when the file is uploaded.

If the file is not valid, the view is shown again and the input type="file" value should be pointing to the file which the upload failed for.

This doesn't seem to work: (code from the view)

<input type="file" name="opt" value="${params.opt}" />

This is rendered to the user:

<input type="file" name="opt" value="org.springframework.web.multipart.commons.CommonsMultipartFile@c9b839">

Any ideas?

Pablo Pazos
  • 3,080
  • 29
  • 42
  • What is happening in the controllers `upload` action? Are you returning any parameters to the view after the upload fails? – john May 24 '15 at 21:04
  • Nope, the view is rendered without passing any model to it. But since the view is rendered in the same request that receives the file and validates it, the view can access 'params', as you can see in my question, the view is rendering the CommonsMultipartFile file that was received, but I think that should be the path of the file in the client. – Pablo Pazos May 25 '15 at 02:33
  • http://stackoverflow.com/questions/11637187/getting-original-file-name-of-uploaded-file-grails maybe this will be of help – V H May 25 '15 at 20:09
  • that will get the name of the file, I think input file needs the complete path on the client to have a value on the field when the page is rendered again. – Pablo Pazos May 25 '15 at 22:28

1 Answers1

0

It seems this is not possible due security reasons, the thing is a server can access client files that might contain private info, if the server knows the path.

More info: How to set a value to a file input in HTML?

I might need to ask the user to select the file again, or do something like AJAX file upload: http://blog.teamtreehouse.com/uploading-files-ajax

Community
  • 1
  • 1
Pablo Pazos
  • 3,080
  • 29
  • 42