The @javax.servlet.annotation.MultipartConfig
annotation is supposed to be placed on the class implementing HttpServlet
, not on a backing bean class. Basically, that annotation has to be placed on the FacesServlet
class, which is already done since JSF 2.2.
In other words, the @MultipartConfig
annotation on your backing bean class is being ignored and has no effect and the file is actually not saved in the location
you specified in the annotation. Instead, it's been saved in a path relative to the so-called current working directory, which is basically the "currently opened folder" at the moment java.exe
is been executed. In case of Java web applications that's usually server's binary folder or so. You can track it down as below:
System.out.println(new File(".").getAbsolutePath());
You'll see your uploaded file there.
Moreover, even if the @MultipartConfig
annotation did work, the location
attribute does actually not represent the permanent file upload save location. Instead, it represents the temporary disk storage location for the case when the uploaded file size exceeds the available/configured memory space. You should never store uploaded files permanently at the location identified by @MultipartConfig(location)
. You should always obtain the file content via Part#getInputStream()
and write it to the desired permanent location provided by a new File
or Path
representing an absolute path.
Get rid of that whole @MultipartConfig
annotation. It's not doing anything useful in a backing bean class. Just obtain the file content by Part#getInputStream()
and copy it to the desired absolute path:
try (InputStream input = imagemCarregada.getInputStream()) {
Files.copy(input, new File("/home/rogerio/tmp/teste.jpg").toPath());
}
See also
Unrelated to the concrete problem, using a session scoped bean for this purpose is not ideal. Rather use a view or request scoped one. See also How to choose the right bean scope? And, using prependId="false"
is not recommended for other purposes than login forms tied to a login framework which doesn't support JSF-prepended ID in request parameter names. See also UIForm with prependId="false" breaks <f:ajax render>.