cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the file size without reading file content (File upload UI )

Former Member
0 Kudos

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.

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member185086
Active Contributor
0 Kudos

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