9

I have a form which has a FileField among other fields. Imagine the user chooses a file, presses submit and another field triggers a ValidationError. When I get back the form, with the errors on the page, what the user chose for the file field is gone. Can I make it appear, or is this a browser thing?

Geo
  • 93,257
  • 117
  • 344
  • 520

1 Answers1

10

This is a browser thing - for security reasons, you can't prepopulate a file input, otherwise it would be easy to trick users into uploading files from their system without their explicit action.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • So, every time, if you make a mistake ( which the client side validation won't catch ), you'll have to upload again? – Geo Jun 01 '11 at 10:32
  • 1
    If there is a field that requires server side validation (checking if a username is taken for example), why not use ajax to validate? – Timmy O'Mahony Jun 01 '11 at 11:35
  • @Daniel Roseman, so what is smallest change we can do to prevent having to upload the files again? I have never done it, but since we can keep the uploaded file in the server (by moving it from the temporary directory to some other place) is there some way we can associate the file uploaded during last trial with the next trial when the user correctly fills the form without any validation error? If we could somehow do that, we would consider file already uploaded and process it accordingly. – Sandeepan Nath Mar 14 '13 at 19:14