This topic is locked
[SOLVED]

 Problem Determining File Size of Upload

11/18/2010 3:20:32 PM
ASPRunnerPro General questions
M
Mike Nagel author

I'm trying to implement the code example that determines if a file is too large to upload:
filesize=lenb(GetUploadedFileContents("file_file_id"))

if filesize>1000000 then

message = "File is too big"

BeforeAdd=false

exit function

end if

BeforeAdd=true
This code is found on page 261 of the 6.3 manual.
When using this code there are a few problems:

  1. When checking the code validity, there's an error on the 'exit function' line saying it's invalid.
  2. When running the application, I get a 500 - Internal server error.
    I've tried modifying the code to eliminate the 'exit function' problem, but that does not get rid of the 500 error.
    The issue is not related to the size of the file I'm uploading, as it works when the file's size is lower than the IIS threshold.
    I tried to eliminate all code but the 'message' line, which worked, so the problem seems to be in getting the filesize value.
    Then, I tried this:
    filesize=1000001

    if filesize>1000000 then

    message="File is too big!"

    BeforeAdd=false

    end if

    if filesize<=1000000 then

    BeforeAdd=true

    end if
    I was hoping to force the issue in case there was a problem in reading the filesize. This did not work either (500 error).
    Has anyone got this code to work? Thanks!

Admin 11/18/2010

As a first step configure IIS to return detailed error message to the client (browser). Then make sure you don't have 'Friendly HTTP error messages' option turned on in IE.
This will allow you to print exact error message that in turn will provide more info on what's not working.

M
Mike Nagel author 11/19/2010



As a first step configure IIS to return detailed error message to the client (browser). Then make sure you don't have 'Friendly HTTP error messages' option turned on in IE.
This will allow you to print exact error message that in turn will provide more info on what's not working.


I've found out a couple of more things. First, the use of the word "filesize" seemed bad. I changed that to "mySize" and was able to add files again. However, when exceeding the imposed limit of 1,000,000, I now get this:
Request object error 'ASP 0104:80004005'
Operation not Allowed
/xxx/include/aspfunctions.asp, line 1823
That particular line is:
postData = Request.BinaryRead(Request.TotalBytes)

Admin 11/19/2010

Mike,
we'll fix the manual, filesize is a function name now and cannot be used as a variable.
In regards to the second issue we need more info.
I would ask you to post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL. 'Demo Account' button can be found on the last screen in the program.

M
Mike Nagel author 11/19/2010



Mike,
we'll fix the manual, filesize is a function name now and cannot be used as a variable.
In regards to the second issue we need more info.
I would ask you to post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL. 'Demo Account' button can be found on the last screen in the program.


I've been hammering away at this, and the code that's causing the trouble is that trying to determine the file size:
mySize = lenb(GetUploadedFileContents("file_FieldName"))
This function constantly returns a value of zero (0). I determined this by setting a message value to mySize (message = mySize) to see what would come out with a small file selected. The application is bombing only if I select a file that exceeds the limit set by IIS.
The name of my field is "file_id", so the code reads:
mySize = lenb(GetUploadedFileContents("file_file_id"))
I don't know if it's getting this zero value because of the name of my field or if there's a problem with either the lenb() or GetUploadedFileContents() functions.

Admin 11/19/2010

I'm a bit confused. How do you want us to help you?

R
Roger 11/20/2010



I've found out a couple of more things. First, the use of the word "filesize" seemed bad. I changed that to "mySize" and was able to add files again. However, when exceeding the imposed limit of 1,000,000, I now get this:
Request object error 'ASP 0104:80004005'
Operation not Allowed
/xxx/include/aspfunctions.asp, line 1823
That particular line is:
postData = Request.BinaryRead(Request.TotalBytes)


You might want to check your metabase settings for IIS. Depending on the ver of IIS (5,6/7) the actual steps vary, but essentially IIS throttles this configuration/value/size (in other words, it may not be an ASPR issue). I am pretty sure of this because this is what I did and the issue went away. Please be careful when editing the IIS Metabase directly, you can render your web surver - Deaf, Dumb and Blind!!!
I assume absolutely no liability or responsibility for any results (unless they're good <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=54618&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />) so please be careful.

  1. Try this first: %systemroot$/system32/inetsrv/metabase.xml. Locate ASPMaxRequestEntityAllowed node, and change to a Reasonable the value. Keep in mind that if you try to upload a file that is too large, you may still have to configure Script Timeouts as well,
  2. If you have II7, do it this way (you won't see the setting in the metabse unless you do this first - and it's always best to use the IIS GUI anyway); Open IIS Manager from the Administrative Tools, Select the Server from the tree structure on the left hand side, Double click on ASP in the right pane. You SHOULD see a list of properties, Expand the Limits Properties and you will see Maximum Request Entity Body Limit. Set the value here in bytes to the upload limit you wish to set. Click Apply. I suggest a restart of the server (I always do this with MS stuff...). Also, try to calculate a multiple of 1024, it will make your life easier when configuring your own parms (which should also be a multiple of 1024) and then add 1024kb to that value. All should be well...

    For ASP.NET try this: limits are configured in the machine.config file of the machine or in the web.config for the application. Adding the following under the <system.web> tag will increase the ASP.net maximum upload to 10Mbin this example.
    <system.web>

    <httpRuntime maxRequestLength="102400" />

    </system.web>
    This one I'm not 100% sure of, but I have a client that did this and he's all good.
    Hope these help.

M
Mike Nagel author 11/22/2010



I'm a bit confused. How do you want us to help you?


Sergey,
I'm looking for a line of code that will return the size of a file before it's uploaded so that I can terminate the process before the record is created. As noted, I've tried the sample code included in the manual, but it does not work for me. This line:
mySize = lenb(GetUploadedFileContents("file_file_id"))
always returns a value of zero when it's supposed to return the size of the file name captured in the field "file_id." Since it returns a value of zero, the only thing that's stopping the upload of large files is the IIS setting (which returns an error when reached).
So either the code in the manual is incorrect or there's something missing on my server and/or client that's keeping the code from working.

M
Mike Nagel author 11/22/2010



This one I'm not 100% sure of, but I have a client that did this and he's all good.
Hope these help.


Roger,
Thanks for the feedback, but I'm already aware of how to throttle IIS to limit uploaded file sizes. This works perfectly. What doesn't work is determining the size of a file beforeit is uploaded.

Admin 11/22/2010

Mike,
I totally understand what you saying and explained what you need to do in order to let us troubleshoot it.

M
Mike Nagel author 1/11/2011



Mike,
I totally understand what you saying and explained what you need to do in order to let us troubleshoot it.


Sergey,
Have you had a chance to look into this issue? Thanks!

Admin 1/11/2011

Mike,
did you post it to Demo Account and sent us a link where we can troubleshoot it?

M
Mike Nagel author 1/12/2011



Mike,
did you post it to Demo Account and sent us a link where we can troubleshoot it?


Sergey,
Uploaded, but without the file size checking code. Let me know if you want me to add it back in and upload again.

Admin 1/12/2011

Mike,
once you uploaded it you need to open a ticket at http://support.xlinesoft.com supplying your Demo Account URL along with instructions on reproducing this issue.