Hello Everyone,
I have code that uploads files in asp. It seems to be working however
on files > 200kb it bombs and i don't know why. Does anyone have any
idea of why this would occur and what i can do to fix it? Thank you in
advance!!!! 10 3500 er************@cowaninsurancegroup.com wrote: Hello Everyone, I have code that uploads files in asp. It seems to be working however on files > 200kb it bombs and i don't know why. Does anyone have any idea of why this would occur and what i can do to fix it? Thank you in advance!!!!
Are you using a component to upload the file? Does that component have
a limit somewhere? If you're using VBScript or serverside Javascript
to do it, can you post the code?
This question cannot be answered in a vacuum.
--
Tim Slattery
MS MVP(DTS) Sl********@bls.gov
Tim Slattery wrote: er************@cowaninsurancegroup.com wrote:
Hello Everyone, I have code that uploads files in asp. It seems to be working however on files > 200kb it bombs and i don't know why. Does anyone have any idea of why this would occur and what i can do to fix it? Thank you in advance!!!!
Are you using a component to upload the file? Does that component have a limit somewhere? If you're using VBScript or serverside Javascript to do it, can you post the code?
This question cannot be answered in a vacuum.
-- Tim Slattery MS MVP(DTS) Sl********@bls.gov
I am not using a component to upload the file and there is a limit but
it's 1024k which is WELL above the files size that i am trying to
upload. I will post the code later tonight as i don't have it with me
at the moment. I am using VBScript and the source code was not created
by me i'm taking it over for another company. I will post the code
around 8pm tonight. thanks
Thanks for your response.
Erin
As promised here is the code, i thikn this is all that is used to do
the uploading (the second function is quite big).. thanks so much for
looking at this!!!!!
The first method called
Sub
ProcessUpload(pau_thePath,pau_Extensions,pau_Redir ect,pau_storeType,pau_sizeLimit,pau_nameConflict,p au_requireUpload,pau_minWidth,pau_minHeight,pau_ma xWidth,pau_maxHeight,pau_saveWidth,pau_saveHeight, pau_timeout)
Server.ScriptTimeout = pau_timeout
pau_doPreUploadChecks pau_sizeLimit
RequestBin = Request.BinaryRead(Request.TotalBytes)
Set UploadRequest = CreateObject("Scripting.Dictionary")
pau_BuildUploadRequest RequestBin, pau_thePath, pau_storeType,
pau_sizeLimit, pau_nameConflict
If pau_Redirect <> "" Then
If UploadQueryString <> "" Then
pau_Redirect = pau_Redirect & "?" & UploadQueryString
End If'
Response.Redirect(pau_Redirect)
end if
End Sub
================================================== =========
pau_builduploadrequest
Sub
pau_BuildUploadRequest(RequestBin,UploadDirectory, storeType,sizeLimit,nameConflict)
Dim Boundary, FormInfo, TypeArr, BoundaryArr, BoundaryPos, Pos, PosLen
Dim PosFile, Name, PosBound, FileName, ContentType, Value, ValueBeg,
ValueEnd, ValueLen
'Check content type
TypeArr = Split(Request.ServerVariables("HTTP_Content_Type") , ";")
if Trim(TypeArr(0)) <> "multipart/form-data" then
Response.Write "<b>Form was submitted with no
ENCTYPE=""multipart/form-data""</b><br/>"
Response.Write "Please correct and <a
href=""javascript:history.back(1)"">try again</a>"
Response.End
end if
'Get the boundary
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,pau_getByteString(chr(13) ))
if PosEnd = 0 then
Response.Write "<b>Form was submitted with no
ENCTYPE=""multipart/form-data""</b><br>"
Response.Write "Please correct and <A
HREF=""javascript:history.back(1)"">try again</a>"
Response.End
end if
boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos = InstrB(1,RequestBin,boundary)
'Get all data inside the boundaries
Do until (boundaryPos=InstrB(RequestBin,boundary &
pau_getByteString("--")))
'Members variable of objects are put in a dictionary object
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Dictionary")
'Get an object name
Pos =
InstrB(BoundaryPos,RequestBin,pau_getByteString("C ontent-Disposition"))
Pos = InstrB(Pos,RequestBin,pau_getByteString("name="))
PosBeg = Pos+6
PosEnd = InstrB(PosBeg,RequestBin,pau_getByteString(chr(34) ))
Name = LCase(pau_getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg)))
PosFile =
InstrB(BoundaryPos,RequestBin,pau_getByteString("f ilename="))
PosBound = InstrB(PosEnd,RequestBin,boundary)
'Test if object is of file type
If PosFile<>0 AND (PosFile<PosBound) Then
'Get Filename, content-type and content of file
PosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,RequestBin,pau_getByteString(chr(34) ))
FileName = pau_getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
FileName =
pau_RemoveInvalidChars(Mid(FileName,InStrRev(FileN ame,"\")+1))
'Add filename to dictionary object
UploadControl.Add "FileName", FileName
Pos = InstrB(PosEnd,RequestBin,pau_getByteString("Conten t-Type:"))
PosBeg = Pos+14
PosEnd = InstrB(PosBeg,RequestBin,pau_getByteString(chr(13) ))
'Add content-type to dictionary object
ContentType = pau_getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "ContentType",ContentType
'Get content of object
PosBeg = PosEnd+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = FileName
ValueBeg = PosBeg-1
ValueLen = PosEnd-Posbeg
Else
'Get content of object
Pos = InstrB(Pos,RequestBin,pau_getByteString(chr(13)))
PosBeg = Pos+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = pau_getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
ValueBeg = 0
ValueEnd = 0
End If
'Add content to dictionary object
UploadControl.Add "Value" , Value
UploadControl.Add "ValueBeg" , ValueBeg
UploadControl.Add "ValueLen" , ValueLen
'Add dictionary object to main dictionary
if UploadRequest.Exists(name) then
UploadRequest(name).Item("Value") =
UploadRequest(name).Item("Value") & "," & Value
else
UploadRequest.Add name, UploadControl
end if
'Loop to next object
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),Requ estBin,boundary)
Loop
Dim GP_keys, GP_i, GP_curKey, GP_value, GP_valueBeg, GP_valueLen,
GP_curPath, GP_FullPath
Dim GP_CurFileName, GP_FullFileName, fso, GP_BegFolder, GP_RelFolder,
GP_FileExist, Begin_Name_Num
Dim orgUploadDirectory
if InStr(UploadDirectory,"""") > 0 then
'on error resume next
orgUploadDirectory = UploadDirectory
UploadDirectory = eval(UploadDirectory)
if err then
Response.Write "<b>Upload folder is invalid</b><br/><br/>"
Response.Write "Upload Folder: " & Trim(orgUploadDirectory) &
"<br/>"
Response.Write "Please correct and <a
href=""javascript:history.back(1)"">try again</a>"
err.clear
response.End
end if
'on error goto 0
end if
GP_keys = UploadRequest.Keys
for GP_i = 0 to UploadRequest.Count - 1
GP_curKey = GP_keys(GP_i)
'Save all uploaded files
if UploadRequest.Item(GP_curKey).Item("FileName") <> "" then
GP_value = UploadRequest.Item(GP_curKey).Item("Value")
GP_valueBeg = UploadRequest.Item(GP_curKey).Item("ValueBeg")
GP_valueLen = UploadRequest.Item(GP_curKey).Item("ValueLen")
'Get the path
if InStr(UploadDirectory,"\") > 0 then
GP_curPath = UploadDirectory
if Mid(GP_curPath,Len(GP_curPath),1) <> "\" then
GP_curPath = GP_curPath & "\"
end if
GP_FullPath = GP_curPath
else
GP_curPath = Request.ServerVariables("PATH_INFO")
GP_curPath = Trim(Mid(GP_curPath,1,InStrRev(GP_curPath,"/")) &
UploadDirectory)
if Mid(GP_curPath,Len(GP_curPath),1) <> "/" then
GP_curPath = GP_curPath & "/"
end if
GP_FullPath = Trim(Server.mappath(GP_curPath))
end if
if GP_valueLen = 0 then
Response.Write "<b>An error has occured saving uploaded
file!</b><br/><br/>"
Response.Write "Filename: " & Trim(GP_curPath) &
UploadRequest.Item(GP_curKey).Item("FileName") & "<br/>"
Response.Write "File does not exists or is empty.<br/>"
Response.Write "Please correct and <a
href=""javascript:history.back(1)"">try again</a>"
response.End
end if
'Create a Stream instance
Dim GP_strm1, GP_strm2
Set GP_strm1 = Server.CreateObject("ADODB.Stream")
Set GP_strm2 = Server.CreateObject("ADODB.Stream")
'Open the stream
GP_strm1.Open
GP_strm1.Type = 1 'Binary
GP_strm2.Open
GP_strm2.Type = 1 'Binary
GP_strm1.Write RequestBin
GP_strm1.Position = GP_ValueBeg
GP_strm1.CopyTo GP_strm2,GP_ValueLen
'Create and Write to a File
GP_CurFileName = UploadRequest.Item(GP_curKey).Item("FileName")
GP_FullFileName = GP_FullPath & "\" & GP_CurFileName
Set fso = CreateObject("Scripting.FileSystemObject")
pau_AutoCreatePath GP_FullPath
'Check if the file already exist
GP_FileExist = false
If fso.FileExists(GP_FullFileName) Then
GP_FileExist = true
End If
if nameConflict = "error" and GP_FileExist then
Response.Write "<b>File already exists!</b><br/><br/>"
Response.Write "Please correct and <a
href=""javascript:history.back(1)"">try again</a>"
GP_strm1.Close
GP_strm2.Close
response.End
end if
if ((nameConflict = "over" or nameConflict = "uniq") and
GP_FileExist) or (NOT GP_FileExist) then
if nameConflict = "uniq" and GP_FileExist then
Begin_Name_Num = 0
while GP_FileExist
Begin_Name_Num = Begin_Name_Num + 1
GP_FullFileName = Trim(GP_FullPath)& "\" &
fso.GetBaseName(GP_CurFileName) & "_" & Begin_Name_Num & "." &
fso.GetExtensionName(GP_CurFileName)
GP_FileExist = fso.FileExists(GP_FullFileName)
wend
UploadRequest.Item(GP_curKey).Item("FileName") =
fso.GetBaseName(GP_CurFileName) & "_" & Begin_Name_Num & "." &
fso.GetExtensionName(GP_CurFileName)
UploadRequest.Item(GP_curKey).Item("Value") =
UploadRequest.Item(GP_curKey).Item("FileName")
end if
on error resume next
GP_strm2.SaveToFile GP_FullFileName
if err then
err.clear
Dim txt_stream, file_bin
Set txt_stream = fso.CreateTextFile(GP_FullFileName, True)
file_bin = pau_getString(MidB(RequestBin, GP_ValueBeg+1,
GP_ValueLen))
txt_stream.Write file_bin
txt_stream.Close
if err then
GP_strm1.Close
GP_strm2.Close
Response.Write "<b>An error has occured saving uploaded
file!</b><br/><br/>"
Response.Write "Filename: " & GP_FullFileName & "<br/><br/>"
if fso.FileExists(GP_FullFileName) then
Dim f
Response.Write "File exists on server!<br/>"
Set f = fso.GetFile(GP_FullFileName)
Response.Write "Attributes(" & f.attributes & "|" &
f.parentfolder.attributes & "): "
if f.attributes and 1 then
Response.Write "ReadOnly "
end if
if f.attributes and 2 then
Response.Write "Hidden "
end if
if f.attributes and 4 then
Response.Write "System "
end if
if f.attributes and 16 then
Response.Write "Directory "
end if
Response.Write "<br/><br/>"
end if
Response.Write "Error # " & CStr(Err.Number) & " " &
Err.Description & "<br/>"
Response.Write "in " & Err.Source & "(" & GP_strm2.state &
")<br/>"
response.End
end if
end if
GP_strm1.Close
GP_strm2.Close
if storeType = "path" then
UploadRequest.Item(GP_curKey).Item("Value") = GP_curPath &
UploadRequest.Item(GP_curKey).Item("Value")
end if
on error goto 0
end if
end if
next
End Sub er************@cowaninsurancegroup.com wrote: As promised here is the code, i thikn this is all that is used to do the uploading (the second function is quite big).. thanks so much for looking at this!!!!!
The first method called
Sub ProcessUpload(pau_thePath, pau_Extensions, pau_Redirect, pau_storeType, pau_sizeLimit, pau_nameConflict, pau_requireUpload, pau_minWidth, pau_minHeight, pau_maxWidth, pau_maxHeight, pau_saveWidth, pau_saveHeight, pau_timeout)
These arguments include a size limit and a timeout value. The size
limit is passed to pau_BuildUploadRequest, which ignores it. The
timeout is used to set Server.ScriptTimeout. If the timeout value is
not large enough, it could be hit before a huge file has finished
uploading.
You never did say just *how* it bombs with a large file. What messages
appear?
Server.ScriptTimeout = pau_timeout pau_doPreUploadChecks pau_sizeLimit
Don't know what pau_doPreUploadChecks does with the size limit - or
what the size limit is, for that matter.
RequestBin = Request.BinaryRead(Request.TotalBytes)
Total size of file(s) to be uploaded, I guess.
Set UploadRequest = CreateObject("Scripting.Dictionary")
I assume that the UploadRequest hash is global, since
pau_BuildUploadRequest uses it
pau_BuildUploadRequest RequestBin, pau_thePath, pau_storeType, pau_sizeLimit, pau_nameConflict
Size limit is passed here, but the sub doesn't use it.
If pau_Redirect <> "" Then If UploadQueryString <> "" Then pau_Redirect = pau_Redirect & "?" & UploadQueryString End If'
Response.Redirect(pau_Redirect) end if End Sub
================================================= ========== pau_builduploadrequest
Sub pau_BuildUploadRequest(RequestBin,UploadDirectory ,storeType,sizeLimit,nameConflict) Dim Boundary, FormInfo, TypeArr, BoundaryArr, BoundaryPos, Pos, PosLen Dim PosFile, Name, PosBound, FileName, ContentType, Value, ValueBeg, ValueEnd, ValueLen
--
Tim Slattery
MS MVP(DTS) Sl********@bls.gov
Hi Tim,
thanks for your reply, actually i just get a 500 internal server error
and that's the extent of it. I am pretty sure it has to do with the
size of the file because any file under 200 kb will upload fine and I
only get the error when i try to upload a bigger file. So if i up the
timeout time and the filesize should that do the trick? or at least is
it a place to start?
Thanks,
Erin
this is pau_doPreUploadChecks
Sub pau_doPreUploadChecks(sizeLimit)
Dim checkADOConn, AdoVersion, Length
'Check ADO Version
set checkADOConn = Server.CreateObject("ADODB.Connection")
on error resume next
adoVersion = CSng(checkADOConn.Version)
if err then
adoVersion = Replace(checkADOConn.Version,".",",")
adoVersion = CSng(adoVersion)
end if
err.clear
on error goto 0
set checkADOConn = Nothing
if adoVersion < 2.5 then
Response.Write "<b>You don't have ADO 2.5 installed on the
server.</b><br/>"
Response.Write "The File Upload extension needs ADO 2.5 or greater to
run properly.<br/>"
Response.Write "You can download the latest MDAC (ADO is included)
from <a
href=""www.microsoft.com/data"">www.microsoft.com/data</a><br/>"
Response.End
end if
'Check content length if needed
Length = CLng(Request.ServerVariables("HTTP_Content_Length" )) 'Get
Content-Length header
If sizeLimit <> "" Then
sizeLimit = CLng(sizeLimit) * 1024
If Length > sizeLimit Then
Response.Write "Upload size " & FormatNumber(Length, 0) & "B exceeds
limit of " & FormatNumber(sizeLimit, 0) & "B<br/>"
Response.Write "Please correct and <a
href=""javascript:history.back(1)"">try again</a>"
Response.End
End If
End If
End Sub
another thing i should mention, i don't get the error message "exceeds
limit of ..." it just simply gives me a 500 internal server error.
Thanks again,
Erin er************@cowaninsurancegroup.com wrote: another thing i should mention, i don't get the error message "exceeds limit of ..." it just simply gives me a 500 internal server error. Thanks again, Erin http://www.aspfaq.com/show.asp?id=2109
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Thanks that's awesome!!
now i am getting an "operation not allowed" on this line
RequestBin = Request.BinaryRead(Request.TotalBytes)
any idea's why????
Thanks
Erin
read the 1st part http://www.powerasp.com/content/hint...mmon_sense.asp
<er************@cowaninsurancegroup.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com... Hi Tim, thanks for your reply, actually i just get a 500 internal server error and that's the extent of it. I am pretty sure it has to do with the size of the file because any file under 200 kb will upload fine and I only get the error when i try to upload a bigger file. So if i up the timeout time and the filesize should that do the trick? or at least is it a place to start? Thanks, Erin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tihon |
last post by:
Hello!
I again need your help, just can't understand whats going on.
Got this upload pictures form and it's having problem handling large
files (~1.5 - 2 MB).
Everything works fine if i just...
|
by: dave |
last post by:
Hello there,
I am at my wit's end ! I have used the following script succesfully to
upload an image to my web space. But what I really want to be able to do is
to update an existing record in a...
|
by: Thomas Due |
last post by:
Hi,
I am writing an ASP.NET project where I allow users to upload files to
the server. I have changed to web.config to allow a total file size of
100MB. My problem is that if the total file size...
|
by: Brian Birtle |
last post by:
**** A CHALLENGE TO THE GURUS - refute the statement "It's impossible
to build a file upload progress meter using ASP.NET" **** First person
to prove me wrong gets "All Time .NET Programming GOD"...
|
by: ricardo corbacho perez |
last post by:
Hi there,
I've been reading all I could find on the control 'input type=file' and all
the trouble that it comes when uploading large binary files (>4MB) to a DB
server or server path.
I've seen...
|
by: jf li |
last post by:
I have a Asp.net web application and a Asp.net Web service application. The
Web application is using HtmlInputFile to get a 50M size of file selected by
end user, read the data of this file and...
|
by: darrel |
last post by:
I briefly researched this a year or so ago for a project that never
materialized, but now I'm in the midst of one and need to look into this a
bit more.
I'm working on a site where the client...
|
by: ll |
last post by:
I'm working with 'pure ASP upload' script which is designed to
redirect to an alert/error message, should
a file larger than the set limit be attempted to be uploaded. The
problem is that, while...
|
by: Bobby Edward |
last post by:
Are there any ASP.NET compatible controls out there that will allow you to
upload large files, up to 2 gb?
Prefer free of course. ;)
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |