Saving the whole way
To save in a database you must save the way as a String
.
Obviously your code that reads and writes the records can encapsulate this String into a File
for example, recovering the String
bank and creating a File
or recovering the file path as String
and recording in the database.
In that situation, do what is most convenient.
Organizing the archives
However, unless it is an absolutely necessary requirement of your system, I would not save the entire file path.
In general, it would be more appropriate to set a directory in the program configuration and save all selected files in that directory.
Then you can save only the names of the images in the database and, when you need to save the file, just do something like:
new File(configuracao.getPastaArquivos(), nomeArquivo)
Besides, the file name isn’t even necessary. If you have, for example, a table in the database where you save the file information, you can simply save the file in the folder using the ID as its name.
So the path on the disk would be something like this:
new File(configuracao.getPastaArquivos(), arquivo.getId())
This way, the file data (like your name) stays in the database and you have everything organized in a folder by ID.
It’s easier to back up, move files to another location if needed, and also avoids problems with special characters in names, spaces, and accents. Also allows situations where two system users send a file with the same name.
If you are going to insert only the path, why not a String ? File.getAbsolutePath() ?
– Josh
The image is selected by the html form. As if it were a Servlet
– Victor Henrique