cancel
Showing results for 
Search instead for 
Did you mean: 

Upload file to a limited size

Former Member
0 Kudos

Hi,

I have a requirement where i have to upload a file and have to restrict the user from uploading the file size more then 100Kb.

How can i achieve this.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Try checking the size of the data xstring of the FileUpload component. The xstring consists of the file content in Hex.

This code will find the number of hex characters in the xstring:

-


(import FileUpload data context attribute with name "filedata")

DATA: length TYPE I.

DATA: datastring TYPE STRING.

datastring = filedata.

length = STRLEN( datastring ).

-


You should be able to determine the file size from the length of the xstring and stop the user from proceeding if the size is too large.

Each hex character in the xstring represents 4 bits.

Former Member
0 Kudos

Thanks Scott for ur valuable help.

What i have done is

DATA: length TYPE I.

DATA: datastring TYPE STRING.

datastring = filedata.

length = STRLEN( datastring ).

size = ( length * 4 / 8 ) / 1024.

It gives the size in Bytes.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Pankaj,

you might have a look at SAP Note [31395|https://service.sap.com/sap/support/notes/31395] "System parameters: Defined where? Displayed how?"

Best regards,

Andreas

Former Member
0 Kudos

Hi Pankaj,

it is possible to restrict the size for files uploaded with FileUpload. Adjust parameter icm/HTTP/max_request_size_KB to a value you expect to be sufficient for your needs.

Best regards,

Andreas

Former Member
0 Kudos

Hi,

How can i set this parameter and where.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

100Kb isn't very much. Keep in mind that this profile parameter gets set for the entire ICM. It is a system parameter and gets set in your instance profile (RZ10). This means the limit will be enforced by all applications, not just your one application.

Former Member
0 Kudos

Hi Thomas,

Actually i am having two applications. In both the applications i have the different file size limitation. Is it possible to achieve.

I can not change for the entire ICM.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

No, there is no parameter that would allow the ICM to control this per application. You would have to check the size on the server as was also suggested - however this is actually a little bit late if you want to avoid the impact on the system of a large file upload. By the time you check in ABAP in the server event, the file is already completely uploaded and in session memory. The nice thing about hte ICM profile is that it checks the estimated request size and can reject the request before processing the upload itself.