My large files (5mb approx) are not opening after being downloaded? I can see the file on my desktop where i saved it too, but when i double click to open it I get an error message from Microsoft Word saying "The document name or path is not valid".
For smaller files they are downloading and opening fine? Any idea as to what could be causing this?
Here is the code from my doGet() method of my servlet:
Integer documentID = new Integer(request.getParameter("documentID"));
Integer employeeID = new Integer(request.getParameter("employeeID"));
DocumentsMgr documentsMgr = documentsMgrHome.create();
Document document = documentsMgr.getDocument(documentID);
if (document != null) {
FTPConnectionMgr connectionMgr = new FTPConnectionMgr(host, user, password);
if (request.getParameter("viewOnly") == null) {
document = documentsMgr.checkOut(documentID, employeeID);
}
byte[] file = connectionMgr.getFile(document.getDocumentTitle());
if (file.length > 0) {
response.setContentType("application/x-download");
response.setHeader("Content-Disposition","attachment; filename=\"" + document.getDocumentTitle() + "\"");
ServletOutputStream out = response.getOutputStream();
//connectionMgr.getFile(out, document.getDocumentTitle());
out.write(file);
out.close();
}
else {
JErrorBean errorBean = new JErrorBean();
errorBean.setErrorMessage("File " + documentID + " exists in the database but not on the file server, please contact an administrator");
request.setAttribute("error", errorBean);
request.getRequestDispatcher("error.jsp").forward(request, response);
}
}
else {
JErrorBean errorBean = new JErrorBean();
errorBean.setErrorMessage("Problem retreiving document");
request.setAttribute("error", errorBean);
request.getRequestDispatcher("error.jsp").forward(request, response);
}
And here is my FTP connection code:
public class FTPConnectionMgr {
private FTPClient ftp;
public FTPConnectionMgr(String host, String user, String password) {
try {
ftp = new FTPClient(host);
ftp.debugResponses(true);
ftp.login(user, password);
ftp.setType(FTPTransferType.BINARY);
ftp.setConnectMode(FTPConnectMode.ACTIVE);
}
catch (IOException ex) {
throw new KMAFTPException(ex);
}
catch (FTPException ex) {
throw new KMAFTPException(ex);
}
}
public byte[] getFile(String remoteFileName) {
try {
byte[] file = ftp.get(remoteFileName);
return file;
}
catch (FTPException ex) {
return new byte[0];
}
catch (IOException ex) {
throw new KMAFTPException(ex);
}
}
}