The enduser won't send you the full client side file path. Even then, if it did, how would you ever get the file contents by only the path? If it were possible, it would have been a huge security breach as basically anyone on the world would be able to unaskingly scrape files from anyone else's disk through the entire Internet.
Usually, only the filename is being sent and you should even not use exactly that filename to save the obtained content on disk in order to avoid files being overwritten in case (another) enduser coincidentally uploads a file with exactly same name. You should use it at most as metadata (e.g. to prefill the Save As filename in case enduser want to download it back at a later moment).
You should actually be interested in the actual file content sent to you in flavor of InputStream
or byte[]
, not the original client side path nor filename. The file content is sent only once and you should immediately read and write it to a more permanent location in the server side once the bean action method hits. Then, keep track of the (autogenerated/predefined!) filenames/paths of those saved files in some List<String>
or List<File>
in the view or perhaps the session scope.
See also: