cancel
Showing results for 
Search instead for 
Did you mean: 

How to limit file size for FileUpload UI element?

former_member182374
Active Contributor
0 Kudos

Hi all,

I'm using the FileUpload UI element in NW2004s SP20.

I want to limit the size of the uploaded file.

The simple option is to load the file to the context, check the size, by using

InputStream stream = resource.read(false);
double size = stream.available();

and report errors if any.

However, I don't want to store huge files in the context or flie system (even temporarily) nor 'spend' network resources for uploading a file that I won't be use...

Is there a way to limit the file size by using some property for the fileUpload UI element in the server?

Is there a way to check the file size before it's uploaded (for example like GMAIL does - checks the file BEFORE the actual upload)

Regards,

Omri

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Omri,

InputStream stream = resource.read(false);
double size = stream.available();

just checking with you, when you can get the size (above code) can't it be possible to put a condition of the file size when increases the limit set by you?

FileOutputStream is written only after you get the size (in bytes)! So you can have a condition before fileOutput.write();

Thanks,

MS

former_member182374
Active Contributor
0 Kudos

Hi,

I have a condition for checking the file's size and nothing is written to the server's disk (but this can be checked AFTER the file was uploaded)

My problem is the network traffic and the CPU load if users are trying to download huge files (if the file is loaded to the context it consumes memory).

I'm looking for a way to limit the request size for a Web Dynpro with a file upload UI element...

Regards,

Omri

Former Member
0 Kudos

Hi Omri,

"(but this can be checked AFTER the file was uploaded)" - what do you really mean here? I mean your main query is to restrict the file upload if it crosses certain size-limit. What is the use if you check the size after upload?

My problem is the network traffic and the CPU load if users are trying to download huge files..., if the upload is restricted for size this download problem will not come .. correct?

Not sure about the UI element properties has something to restrict the size, and if its really related to Network traffic and CPU utilization, i think you've to check with Basis team to re-sizing the servers to meet this new requirement of upload/download if its not considered before.

Or the last option i could see is to use KM Upload iView if sizing is done with these considerations.

Thanks,

MS

Answers (1)

Answers (1)

Former Member
0 Kudos

we define a WebDynPro context attribute in the view contoller , for e.g. context attribute with name excelFileResource of type com.sap.ide.webdynpro.uielementdefinitions.Resource and bind it to the respective property of fileUpload UI control.

Try this one

IPrivateUploadFileView.IContextElement element = wdContext.currentContextElement();

IWDResource resource = element.getExcelFileResource();

If(resource != null)

{

InputStream stream = resource.read(false);

}