patched download external image for version id
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@144265 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
40cb42d349
commit
7f631e7323
|
@ -18,6 +18,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.common.homelibary.model.versioning.WorkspaceVersion;
|
||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
|
||||
|
@ -255,7 +256,20 @@ public class DownloadServlet extends HttpServlet{
|
|||
if(versionID!=null){
|
||||
logger.info("Downloading version id: "+versionID);
|
||||
//TODO MUST BE ADDED SIZE FOR VERSIONED FILE
|
||||
WorkspaceVersion vers = externalFile.getVersion(versionID);
|
||||
if(vers!=null){
|
||||
long versionSize = vers.getSize(); //just one read
|
||||
versionSize = versionSize>0?versionSize:-1;
|
||||
if(versionSize>0)
|
||||
resp = setContentLength(resp, versionSize);
|
||||
|
||||
is = externalFile.downloadVersion(versionID);
|
||||
}else{
|
||||
logger.error("Error file version "+versionID+" not found in the server-side. Refresh and try again.");
|
||||
handleError(urlRedirectOnError, req, resp, itemId, HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": Error file version "+versionID+" not found in the server-side. Refresh and try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
}else{
|
||||
resp = setContentLength(resp, externalFile.getLength());
|
||||
is = externalFile.getData();
|
||||
|
@ -286,9 +300,30 @@ public class DownloadServlet extends HttpServlet{
|
|||
String contentDisposition = viewContent?"inline":"attachment";
|
||||
resp.setHeader( "Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );
|
||||
resp.setContentType(externalImage.getMimeType());
|
||||
InputStream is;
|
||||
if(versionID!=null){
|
||||
logger.info("Downloading version id: "+versionID);
|
||||
//TODO MUST BE ADDED SIZE FOR VERSIONED FILE
|
||||
WorkspaceVersion vers = externalImage.getVersion(versionID);
|
||||
if(vers!=null){
|
||||
long versionSize = vers.getSize(); //just one read
|
||||
versionSize = versionSize>0?versionSize:-1;
|
||||
if(versionSize>0)
|
||||
resp = setContentLength(resp, versionSize);
|
||||
|
||||
is = externalImage.downloadVersion(versionID);
|
||||
}else{
|
||||
logger.error("Error file version "+versionID+" not found in the server-side. Refresh and try again.");
|
||||
handleError(urlRedirectOnError, req, resp, itemId, HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": Error file version "+versionID+" not found in the server-side. Refresh and try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
}else{
|
||||
resp = setContentLength(resp, externalImage.getLength());
|
||||
is = externalImage.getData();
|
||||
}
|
||||
|
||||
OutputStream out = resp.getOutputStream();
|
||||
InputStream is = externalImage.getData();
|
||||
IOUtils.copy(is, out);
|
||||
is.close();
|
||||
|
||||
|
|
Loading…
Reference in New Issue