If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > XMLHTTP Binary file upload ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-01-03, 21:31
jamesO jamesO is offline
Registered User
 
Join Date: Sep 2003
Posts: 16
Unhappy XMLHTTP Binary file upload ?

Hello

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.
Quote:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<HTML>
<HEAD>

<%
Dim strURL
Dim fileName

sfileName = Request.QueryString("theFile")

sData = getFileBytes(sfileName) ', sType)
sfileName= mid(sfileName, InStrRev(sFileName,"\")+1,len(sfileName))
Dim xmlhttp
Set xmlhttp=createobject("MSXML2.XMLHTTP.3.0")
strURL = "http://" & request.ServerVariables("HTTP_HOST") & "/dbase/pictures/" & sFileName
xmlhttp.Open "PUT", strURL, False
xmlhttp.Send sData
Set xmlhttp=Nothing

response.Redirect Request.QueryString("theNextPage")

Function getFileBytes(flnm) ', sType)
Dim objStream
Set objStream = CreateObject("ADODB.Stream")
objStream.Type = 1 ' adTypeBinary
objStream.Open
objStream.LoadFromFile flnm
getFileBytes=objStream.Read
objStream.Close
Set objStream = Nothing
End Function

%>
</HEAD>

<body>

</body>
</HTML>
The server is Win2000 and I'm using IE6.

Regards,
James
Reply With Quote
  #2 (permalink)  
Old 10-02-03, 01:48
Bullschmidt Bullschmidt is offline
Guru
 
Join Date: Jun 2003
Location: USA
Posts: 1,032
enctype="multipart/form-data"

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
http://www.aspzone.com/articles/john/aspUpload
__________________
J. Paul Schmidt, Freelance Web and Database Developer
www.Bullschmidt.com
Access Database Sample, Web Database Sample, ASP Design Tips
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On