Foren
Downloading file not showing file size to be downloaded.
Jitender Dhiman, geändert vor 9 Jahren.
Downloading file not showing file size to be downloaded.
Junior Member Beiträge: 29 Beitrittsdatum: 21.09.12 Neueste Beiträge
Hi team,
My code is working to download a file from portlet but in browser ,while downloading, it do not show file size to be downloaded.
I have also set the content length in resourceresponse but its not working.
Please help.
Thanks in advance.
My code is working to download a file from portlet but in browser ,while downloading, it do not show file size to be downloaded.
I have also set the content length in resourceresponse but its not working.
Please help.
String mimetype = doc_file.getMimeType();
if (mimetype == null)
{
mimetype = "application/octet-stream";
}
res.setContentType(mimetype);
System.out.println("Size in header >>> "+(int)doc_file.getSize());
res.addProperty( HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""+DocumentUtil.docNamingConvention(doc_file.getTitle(), "get") +"."+doc_file.getExtension()+"\"" );
res.addProperty(HttpHeaders.CONTENT_LENGTH,Long.toString(doc_file.getSize()));
//res.setContentLength(37402);
OutputStream out=null;
out = res.getPortletOutputStream();
FileInputStream input = (FileInputStream) doc_file.getContentStream();
byte[] buf=new byte[4096];
int bytesread = 0, bytesBuffered = 0;
while( (bytesread = input.read( buf )) > -1 ) {
out.write( buf, 0, bytesread );
bytesBuffered += bytesread;
if (bytesBuffered > 1024 * 1024) { //flush after 1MB
bytesBuffered = 0;
out.flush();
//System.out.print();
}
}
prefMM.setValue("downloadS", "done"); /// updating prefrence
prefMM.store();
input.close();
out.close();
Thanks in advance.
Jitender Dhiman, geändert vor 9 Jahren.
RE: Downloading file not showing file size to be downloaded.
Junior Member Beiträge: 29 Beitrittsdatum: 21.09.12 Neueste Beiträge
showing three posts on this thread but none is visible.....
Anhänge: