Thread: XMLHTTP Binary file upload ?
10-01-03, 21:31 #1Registered User
- Join Date
- Sep 2003
Unanswered: XMLHTTP Binary file upload ?
I have an application that uploads pictures into a folder on the server. For various reasons I can't use a simple enc-type form. The following code works perfectly when executed on the server, but not on any workstations. On my development box I can execute it locally but not from the server.
sfileName = Request.QueryString("theFile")
sData = getFileBytes(sfileName) ', sType)
sfileName= mid(sfileName, InStrRev(sFileName,"\")+1,len(sfileName))
strURL = "http://" & request.ServerVariables("HTTP_HOST") & "/dbase/pictures/" & sFileName
xmlhttp.Open "PUT", strURL, False
Function getFileBytes(flnm) ', sType)
Set objStream = CreateObject("ADODB.Stream")
objStream.Type = 1 ' adTypeBinary
Set objStream = Nothing
10-02-03, 01:48 #2Guru
- Join Date
- Jun 2003
First let's deal with the timeout issue which can be a problem if a user is uploading a fairly large file (although perhaps you don't want the timeout increased too much because you DON'T want a user uploading a large file).
For pure ASP (i.e. non component) solutions (and I believe this would be true for component solutions too) can increase the timeout for the page:
' Script timeout in seconds for this page.
' (60 x 60 = 1 hour.)
Server.ScriptTimeout = 60 * 60
Also the Anonymous Internet user needs Change permission on the folder that a file is going to be uploaded to and actually Full Access might be better if you are later going to use the FileSystemObject to delete a file.
And whatever file uploading solution you use, on the page in question you will no longer be able to refer to regular form fields with Request.Form("MyField"). Instead there will be some kind of proprietary way to refer to the fields.
Here is a resource for letting the user upload a file which is something that was unfortunately not built into ASP:
ASP File Upload Using VBScript by John R. Lewis - 7/10/2000