0
I upload files to a folder, which works when running in eclipse. But when I try to upload through some browser, I am not allowed due to the security of it.
My question is, is there any way to get the browser to return the file location? Or if there is any way to upload the file to copy it to the destination folder?
If necessary to prepare a reply I leave below my code.
//caminho relativo da pasta destino
final String Dest = System.getProperty("user.dir") + "/";
public void addMusica(String musica_nome, Part musica, String ano) throws IOException {
String fileName = getFileName(musica);
File data = null;
try {
File music = new File(fileName);
data = new File(Dest + music.getName());
Files.copy(music.toPath(), data.toPath());
} catch (Exception e) {
e.printStackTrace();
}
}
//tratamento do path
private String getFileName(Part part) {
final String partHeader = part.getHeader("content-disposition");
for (String content : part.getHeader("content-disposition").split(";")) {
if (content.trim().startsWith("filename")) {
return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");
}
}
}
No. This is a Feature browser precisely to protect the user from having the disk structure accessed. I, for example, don’t want any website to know about my family photos stored in C: notporn reallynotporn Juju.png. If you need access to the user’s disk, maybe you should rethink the design of your application, Maybe web is not the way.
– Renan Gomes
You want a website to access/control the user’s machine?
– Guilherme Nascimento
@Renan sometimes I see a text of you and I wonder if it was I who wrote it?
– Oralista de Sistemas
If I type @Renan I index who?
– Don't Panic
@Guilhermenascimento not only want to upload files, I’ve never done it before but I have a project in mind that might be something for me
– Bruno Gibellino
@Everson I received the notification.
– Oralista de Sistemas
But if you want to upload then what is the need to get the location?
– Guilherme Nascimento
Ou se existe alguma forma de enviar o file para poder copiá-lo para a pasta destino
A control<input type="file">
does just that.– Oralista de Sistemas
This using
Servlet
?– Guilherme Nascimento
@Renan if that is so, then the problem is in the back-end, the JSP does not treat the upload "alone" has to write the
doPOST
– Guilherme Nascimento
@Guilhermenascimento Yes I’m using Servlet.
– Bruno Gibellino