on 03-02-2009 12:29 PM
Hi Experts,
How to get the uploaded file size without reading IWDResource ????
with below coding i am getting file size
wdContext.currentContextElement().getSupport_File_Elem().read(false).available()
But with above code file is reading and returning the file size. Without reading the file content is there any way to get the file size.
My requirement is to put validation while uploading the file(with above code it is taking time for simple validation) .
Regards,
Satya.
Hi Satya
At least identification of the resource in necessary later it depends whether u want to process it or not.
Well see the code if it relevant to you
if (element.getFileResource() != null)
{
IWDResource resource = element.getFileResource();
if (resource.getResourceType().getFileExtension().equals("xls"))
{
wdContext.currentUploadFileInformationElement().setFileName("File Name : " + resource.getResourceName());
wdContext.currentUploadFileInformationElement().setFileSize("File Size : " + getFileSize(resource));
}
}
//Method for File Size
public java.lang.String getFileSize( com.sap.tc.webdynpro.services.sal.datatransport.api.IWDResource resource ) {
//@@begin getFileSize()
InputStream stream = null;
DecimalFormat myFormatter = new DecimalFormat("###.##");
double size = 0;
String unit = "";
try
{
stream = resource.read(false);
size = stream.available();
size = stream.available();
stream = resource.read(false);
size = stream.available();
if (size < 1024)
{
unit = " Bytes";
} else if (size < 1048576)
{
size = size / 1024;
unit = " KB";
} else if (size < 1073741824)
{
size = size / 1024 / 1024;
unit = " MB";
}
}
catch (IOException e)
{
wdComponentAPI.getMessageManager().reportException(e.getLocalizedMessage());
}
return myFormatter.format(size) + unit;
Hope it help you
Best Regards
Satish Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.