Solved

ASP Upload - Size Restrictions?

Posted on 2004-09-30
24
1,396 Views
Last Modified: 2008-01-09
I have a CMS in place for a site that required uploading of media files (ie. .wmv, .mp3, .mov). I have the paths/permissions/uploading figured out, but the script I'm using appears to have some kind of size restriction so that anything over 300kb fails -- and I can't seem to find where this limit it set (if it exists at all!) I have a reasonable working knowledge of ASP, but cannot see what I need to amend here -- can someone take a peek and let me know what I need to do?

The upload script I'm using is below:

<%
'***************************************
' File:        Upload.asp
' Author: Jacob "Beezle" Gilley
' Date:   12/07/2000
'****************************************

Class FileUploader
      Public  Files
      Private mcolFormElem

      Private Sub Class_Initialize()
            Set Files = Server.CreateObject("Scripting.Dictionary")
            Set mcolFormElem = Server.CreateObject("Scripting.Dictionary")
      End Sub
      
      Private Sub Class_Terminate()
            If IsObject(Files) Then
                  Files.RemoveAll()
                  Set Files = Nothing
            End If
            If IsObject(mcolFormElem) Then
                  mcolFormElem.RemoveAll()
                  Set mcolFormElem = Nothing
            End If
      End Sub

      Public Property Get Form(sIndex)
            Form = ""
            If mcolFormElem.Exists(LCase(sIndex)) Then Form = mcolFormElem.Item(LCase(sIndex))
      End Property

      Public Default Sub Upload()
            Dim biData, sInputName
            Dim nPosBegin, nPosEnd, nPos, vDataBounds, nDataBoundPos
            Dim nPosFile, nPosBound

            biData = Request.BinaryRead(Request.TotalBytes)
            nPosBegin = 1
            nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
            
            If (nPosEnd-nPosBegin) <= 0 Then Exit Sub
             
            vDataBounds = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
            nDataBoundPos = InstrB(1, biData, vDataBounds)
            
            Do Until nDataBoundPos = InstrB(biData, vDataBounds & CByteString("--"))
                  
                  nPos = InstrB(nDataBoundPos, biData, CByteString("Content-Disposition"))
                  nPos = InstrB(nPos, biData, CByteString("name="))
                  nPosBegin = nPos + 6
                  nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))
                  sInputName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
                  nPosFile = InstrB(nDataBoundPos, biData, CByteString("filename="))
                  nPosBound = InstrB(nPosEnd, biData, vDataBounds)
                  
                  If nPosFile <> 0 And  nPosFile < nPosBound Then
                        Dim oUploadFile, sFileName
                        Set oUploadFile = New UploadedFile
                        
                        nPosBegin = nPosFile + 10
                        nPosEnd =  InstrB(nPosBegin, biData, CByteString(Chr(34)))
                        sFileName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
                        oUploadFile.FileName = Right(sFileName, Len(sFileName)-InStrRev(sFileName, "\"))

                        nPos = InstrB(nPosEnd, biData, CByteString("Content-Type:"))
                        nPosBegin = nPos + 14
                        nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
                        
                        oUploadFile.ContentType = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
                        
                        nPosBegin = nPosEnd+4
                        nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
                        oUploadFile.FileData = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
                        
                        If oUploadFile.FileSize > 0 Then Files.Add LCase(sInputName), oUploadFile
                  Else
                        nPos = InstrB(nPos, biData, CByteString(Chr(13)))
                        nPosBegin = nPos + 4
                        nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
                        If Not mcolFormElem.Exists(LCase(sInputName)) Then mcolFormElem.Add LCase(sInputName), CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
                  End If

                  nDataBoundPos = InstrB(nDataBoundPos + LenB(vDataBounds), biData, vDataBounds)
            Loop
      End Sub

      'String to byte string conversion
      Private Function CByteString(sString)
            Dim nIndex
            For nIndex = 1 to Len(sString)
               CByteString = CByteString & ChrB(AscB(Mid(sString,nIndex,1)))
            Next
      End Function

      'Byte string to string conversion
      Private Function CWideString(bsString)
            Dim nIndex
            CWideString =""
            For nIndex = 1 to LenB(bsString)
               CWideString = CWideString & Chr(AscB(MidB(bsString,nIndex,1)))
            Next
      End Function
End Class

Class UploadedFile
      Public ContentType
      Public FileName
      Public FileData
      
      Public Property Get FileSize()
            FileSize = LenB(FileData)
      End Property

      Public Sub SaveToDisk(sFilePath)
            Dim oFS, oFile
            Dim nIndex
      
            Set oFS            = Server.CreateObject("Scripting.FileSystemObject")
            Set oFile      = oFS.CreateTextFile(sFilePath, True)
            
            For nIndex = 1 to LenB(FileData)
                oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))
            Next

            oFile.Close
      End Sub
      
      Public Sub SaveToDatabase(ByRef oField)
            If LenB(FileData) = 0 Then Exit Sub
            
            If IsObject(oField) Then
                  oField.AppendChunk FileData
            End If
      End Sub

End Class
%>
<%
            ' Files are uploaded to the "assets" folder on the web site root.
            sDirUrl = "/assets/"
            
            cSysRootDir = Server.MapPath( sDirUrl )
            If Right( cSysRootDir, 1 ) <> "\" Then
                  cSysRootDir = cSysRootDir & "\"
            End If

            Set Uploader = New FileUploader
            Uploader.Upload()

            KolkoSlika = Uploader.Files.Count

            If Uploader.Files.Count > 0 Then
                  For Each oFile in Uploader.Files.Items
                        sName = oFile.FileName
                        oFile.SaveToDisk cSysRootDir & sName
                        strSlika = sDirUrl & sName
                  Next
            End If

            Set Uploader = Nothing

            Response.Write "<strong>File uploaded. Number of uploaded files: " & cstr(KolkoSlika) & "</strong><br><br>"
            Response.Write "<SCRIPT language=javascript>window.opener.setImage('" + strSlika + "') ; window.close();</" + "SCRIPT>"
%>
0
Comment
Question by:blurredvision
  • 11
  • 9
  • 2
  • +2
24 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 12197180
Hi blurredvision,

Not too sure if this pertains to ASP, but you can try to put this form field above your input file:

<input type="hidden" name="MAX_FILE_SIZE" value="300000">

If that doesn't work, you can always compare the file size using uploadFileVar.Size

Regards,
Zyloch
0
 

Author Comment

by:blurredvision
ID: 12197391
Thanks Zyloch -- the first suggestion didn't help, I'm afraid. And I'm not sure how to go about using the second one....perhaps my 'reasonable working knowledge' of ASP is a little less reasonable that I first thought.

Any ideas? It still strikes me as odd that I cannot find any maximum filesize setting in the Upload script -- there must surely be something that forces the upload to fail for files above 300kb. I have sucessfully uploaded files of varying formats (media, image, docs) -- the upload script is part of the fckeditor (www.fredck.com/fckeditor) and I have been through the support forums there but there doesn't seem to be anything about an upload size limit.

0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12197426
I must confess my knowledge of ASP may be worse than yours, but check out this page: http://www.asp-php.co.uk/en/asp-php/upload.php?page=2&skin=print
0
 
LVL 6

Expert Comment

by:Fahdmurtaza
ID: 12197907
I think that you should backup this one script and replace it by onother uploading script  and then check out whether the  pr oblem is same. If not, then  enjoy it and if yes then there is somewhat problem with the web host youy are dealing with. Check out your host's policies. Moreover, have you checked it with PWS/ IIS ?
Regards,
Fahd Murtaza.
0
 
LVL 14

Expert Comment

by:huji
ID: 12198403
Hi

Well I have been working with that piece of code several times, and it didn't fail for me. There is no file size restriction indeed.
But the key to your question: There is another limit: A limit in time of process. There may be a timeout in request or response, which restricts you with that file sizes. We should be finding that, and I will be looking for that in my version of that ASP uploader thing.
For now, all I can ensure you about is that there is not a file size limit. I have uploaded 20MB from a computer in the same LAN with the server, successfully once!

Wish I can help
Huji
0
 
LVL 14

Expert Comment

by:huji
ID: 12198482
You may set the script time out like this:
<% Server.ScriptTimeout = 300 %>
So set this to the required amount of time, in seconds. The default value is 90 seconds.
0
 

Author Comment

by:blurredvision
ID: 12198492
Zyloch, thanks for the link.

Fahdmurtaza, I have used the same webhost to upload 7mb files without issue (albeit using a different script). I have tried on local IIS, but it keeps hanging (rather than failing!)

Huji, thanks for confirming the lack of filesize limit -- I certainly couldn't find anything reinforcing the idea that one existed. In regards to the timeout, I get the error message after only about 20 seconds... (on DSL)

It seems to me that there must be something inherently simple that I'm missing, and whilst I could use another script I would rather discover what is causing the problem I'm experiencing!
0
 

Author Comment

by:blurredvision
ID: 12198509
Huji, I've just tried using the <% Server.ScriptTimeout = 300 %> atop the code, and it still fails (it actually only takes 5 seconds, not 20 as I previously thought!)

0
 
LVL 14

Expert Comment

by:huji
ID: 12198513
By the way, this ASP uploader you are using is ASP101's one, which is not so fast indeed. I advise you to have a look at this, for further details:
http://www.taka.nl/programming/asp/comparing_fileu
(The link used to work but it is not working any more. I placed a saved version of it here for you: http://ssrc.tums.ac.ir/EE/upload.mht)
Wish I can help
Huji
0
 
LVL 14

Expert Comment

by:huji
ID: 12198524
Well after reading the above link, I hope you decide to use other ASP uploaders. But besides that we may continue working on finding the problem in the current version.
I will be testing that on my own machine and tell you the result.
Huji
0
 

Author Comment

by:blurredvision
ID: 12198530
Thanks Huji -- I'll look into that and let you know how I get on...
0
 
LVL 14

Expert Comment

by:huji
ID: 12198552
Yes! It worked for me: only the first time I ran the code I had an error on line 120 (where SaveToDisk method is firstly defined) but I solved with with giving a correct path to the function when it is later called on the line 156 of the code.
I can not figure your problem with this little information. The code is working at least. I would like to see your code working online, and test it for errors.
Can you upload it somewhere and send me the link? If it is a local site, you may register a free ASP web host like 7host.com for a little space and upload it there for me.
Huji
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:blurredvision
ID: 12198611
I'll pop it on some serverspace of my own -- take a look at www.blurredvision.com.au/cms and login with u:test p:test

I would be most grateful for any light you can shine on this for me...

0
 
LVL 14

Expert Comment

by:huji
ID: 12199754
Well I visited this page now, logged in successfully, but found not where to upload a file. Please help me with navigation!
Huji
0
 

Author Comment

by:blurredvision
ID: 12205805
In the Rich Text Editor if you select any of the text and click on the "LINK" button then a dialog box opens which prompts you to select a local file and send it to the server...  
0
 
LVL 14

Accepted Solution

by:
huji earned 125 total points
ID: 12208054
Hi
First something off topic: I liked your Rich text Editor. I'd never seen it before. Can you provide some info about where it comes from please? (I hope you don't forget this question, while you read the large remaining of the text here!)
Well this is the result of my tests:
I uploaded a little 1K text file first, it worked;
I uploaded a ~40K image then, it again worked;
Then a 396K photo, and it didn't work!!
By the term "it worked" I mean that the little white browser window got open, my network icon showed that my PC and the server are busy transfering data, and it did not close very soon.
But the third one didn't work giving me this error message:

Request object error 'ASP 0101 : 80004005'

Unexpected error

/CMS/filemanager/upload/asp/class_upload.asp, line 60

The function returned |.

And I don't know what is there in line 60. But I know that the little window was open and the connection was actively sending for about two mintues 15 seconds, and then it stopped with that error message in the little window.
Second point: When I clicked the "Browse Server" button I got an error message like this:

Microsoft VBScript runtime error '800a004c'

Path not found

/CMS/filemanager/browse/sample_asp/file_browse.asp, line 47

Which normally occurs when you try to reach a folder with File System Object on your server, which does not really exist.
These are two seperate errors. The first one I think, is more related to a timeout on the server. The second is a coding error.
For your knowledge: The first file was named JS.txt , the second one was image-display9.jpg , and the third one which I could not upload was 1055457-cd6e92c90e1bb23f[1].jpg
You can check and see if the first two are uploaded and the third one is not.
On the other hand I uploaded the third file using a same code on another server on the net, successfully. So I decide to say that the main problem is with timeouts. In my code I just use this line of code to ensure that the files of sizes of my interest will not finish the timeout when being uploaded from home modems:
server.ScriptTimeout=1000
Please add this line of code to your class_upload.asp file and retry the upload test yourself. Report the results here for me too.

Thanks
Huji
0
 

Author Comment

by:blurredvision
ID: 12210061
Hi Huji,

The original RTE came from www.fredck.com/fckeditor and is open source. I've been looking at a few of these (Richeditor, HTMLArea...etc) and found this one to work best for me.

Thanks for running the tests you have -- the Browse Server is looking for a path that doesn't exist (I only uploaded the necessities to the server to show the upload fail), and I still get that failure after only 5 seconds, so I'm quite impressed by your 2 minutes 15 seconds!

I'll try adding the server.ScriptTimeout=1000 line a little later today and let you know what happens.

0
 

Author Comment

by:blurredvision
ID: 12211900
Huji, I tried the server.ScriptTimeout line and this didn't help -- but I did test the script on another server and found it to work fine with files over 1mb in size, thus drawing the conclusion that this appears to be a server configuration problem rather than anything I've done (which is something of a relief, but still frustrating!) -- I'll get in touch with the server administrator and confirm what was causing the problem once it's all sorted.
0
 
LVL 14

Expert Comment

by:huji
ID: 12212801
In Control Panel go to Administrative Tools then IIS, then right click on your site, then under the Directory tab press Configuration... button, go to options, and then set the ASP script time out.
And something else: You say that you get a 5second failure on the same server that I got a 2 minutes failure on? It is odd. This may be from the client side. Retry from other client computer, which is connected to the internet from another gateway. (Not in the same network, or from the same ISP.)
Wish I can help
Huji
0
 
LVL 2

Expert Comment

by:javazoom
ID: 12218009
Hi,

The real limit of HTTP upload is POST limit of web server. For apache, it's 2GB. A solution to get rid of this limit is to split file to upload in chunks and to upload chunks with a client-side applet or activeX. We provide an Applet (client-side) + JSP script (server-side) that implements this feature :

jClientUpload Applet :
http://www.javazoom.net/applets/jclientupload/jclientupload.html

UploadBean :
http://www.javazoom.net/jzservlets/uploadbean/uploadbean.html

For ASP, you could try "smart asp upload" script on server-side.

I hope it helps.
0
 

Author Comment

by:blurredvision
ID: 12246983
I only just got a response from the server administrator -- see below for what will hopefully prove to be the solution to this one...

"I have found the issue that causing the upload page turn into “file not find or something”. I’m not sure how and when after the service patch that set the uploadreadaheasize back to 48KB. I will set to 5MB across to all server, but it requires restart IIS. I will do it at night so it will solve your problem.

Following link regards to the issue:
http://www.motobit.com/help/scptutl/pa33.htm#pnf
http://www.microsoft.com/windows2000/en/server/iis/default.asp?url=/windows2000/en/server/iis/htm/asp/apro9l5x.htm"

Stay tuned for the next round of testing tomorrow morning, and I'll report whether "yay" or "nay" shortly thereafter.
0
 
LVL 14

Expert Comment

by:huji
ID: 12247174
We are still listening, and hoping!
Huji
0
 

Author Comment

by:blurredvision
ID: 12265664
It didn't work, although neither myself nor the server admin can figure out what is going on. He can upload using the ASPSmartUpload.dll files of 5mb in size, which I can also do with my script on another server, but not his. Perplexing. At this stage I may simply use the ASPSmartUpload option rather than the upload class that formed part of the CMS. I will keep reporting back here whatever happens...
0
 

Author Comment

by:blurredvision
ID: 12419057
It has mysteriously started working now, with the server admin claiming to not have changed anything but then neither have I! Will remain a mystery. Points go to Huji for sticking with me on this one...

0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now