I am developing an application Java Web App mounted on Apache Tomcat 8.0.27 . Both in the Internet Explorer browser and Google Chrome , I get errors when I try to show some file that I have deposited locally on my machine.
The possible downloads that you can make in the application are PDF or XML . I dynamically fill a data table in which the buttons have the paths to the files.
The buttons have the following routes:
C: \ PortalLeal \ some.pdf or C: \ PortalLeal \ some.xml
But when I click on any button, it sends me the following error messages:
This is the error message in Chrome:
This is the error message in Internet Explorer:
The way in which I fill the table from Java is this, where I validate if in the database the record has: Both routes (PDF, XML), only the route PDF or just XML, and based on that, I filled the table:
if(null != fac.getRutaPDF() && !fac.getRutaPDF().equalsIgnoreCase("") && null != fac.getRutaXML() && !fac.getRutaXML().equalsIgnoreCase("")){
root.addProperty("accion",
(null != fac.getRutaPDF() ? "<a onClick=\"downloadURI('"+fac.getRutaPDF().replace("\", "\\")+"','"+nombreFilePDF+"');\" class=\"btn red btn-xs tooltips\"><i class=\"fa fa-file-pdf-o\"></i> PDF</a>" : "") +
(null != fac.getRutaXML() ? "<a onClick=\"downloadURI('"+fac.getRutaXML().replace("\", "\\")+"','"+nombreFileXML+"');\" class=\"btn green btn-xs tooltips\"><i class=\"fa fa-file-excel-o\"></i> XML</a>" : "")
);
} else if(null != fac.getRutaPDF() && !fac.getRutaPDF().equalsIgnoreCase("")){
root.addProperty("accion",
(null != fac.getRutaPDF() ? "<a onClick=\"downloadURI('"+fac.getRutaPDF().replace("\", "\\")+"','"+nombreFilePDF+"');\" class=\"btn red btn-xs tooltips\"><i class=\"fa fa-file-pdf-o\"></i> PDF</a>" : "")
);
} else if(null != fac.getRutaXML() && !fac.getRutaXML().equalsIgnoreCase("")){
root.addProperty("accion",
(null != fac.getRutaXML() ? "<a onClick=\"downloadURI('"+fac.getRutaXML().replace("\", "\\")+"','"+nombreFileXML+"');\" class=\"btn green btn-xs tooltips\"><i class=\"fa fa-file-excel-o\"></i> XML</a>" : "")
);
}
Note: I noticed some problems when trying to show the files, so I had to apply the .replace("\", "\\")
so that the route really was: C: \\ PortalLeal \\ algun.pdf
The <a>
tags execute a downloadURI () javascript routine, which receives the full path ( C:\\PortalLeal\\algun.pdf
) from parameters, and the file name ( algun.pdf
).
<script>
function downloadURI(uri, name) {
var link = document.createElement("a");
link.download = name;
link.href = uri;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
delete link;
}
</script>
(This method is the one that does the magic to show the files)
I did a test manually upload a file to C: \\ PortalLeal \\, and manually put the path in some database record and curiously sometimes, it does show the document (only in IExplorer ), and it shows it in the following way:
I do not know if the problem is giving ApacheTomcat or the web browser, for the permissions in the Windows folders.