Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003
    Posts
    16

    Unhappy Unanswered: 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.
    <%@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

  2. #2
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •