SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Posting imagefile to remote server with ServerXMLHTTP

    Hi, i have searched around for a while trying to solve my problem.
    I am making an application where the user can upload a imagefile to my IIS server with ASP. The form in the upload page is like this. This is a regular html page not an asp or aspx page.

    <html>
    <body>
    <form method=post encttype="multipart/form-data" action="http://s1/upload.aspx">
    <input type=hidden name=dir value="/Uploaded/">
    <input type=file name=filedata>
    <input type=submit name=button value='upload'>
    </form>
    </body>
    </html>

    Then in my aspx page i want to change the filename of the uploaded imagefile, and the repost the form with the same imagefile to a unix/apache webserver with the exact same fields and info except for the changed filename. If neccesarry i can store the image locally on my IIS serverl.

    I have no control over the unix/apache upload file as this is a part of another application that we do not have the option to change.

    It must be possible to do this with ServerXMLHTTP or something similar?
    Can anybody help me and include some code samples?

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The closest I found to something similar is
    http://www.15seconds.com/Issue/010522.htm
    but it requires you recode your apache upload file mechanism.

    I can see it might be possible using serverXMLHTTP but the problem is how to encode the file and the rest of the form parameters into 1 request body, to use the send() method.

    Good luck, let us know how you get on.

  3. #3
    eXtremE StorMeR
    Join Date
    Jan 2005
    Location
    Pakistan
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good luck

  4. #4
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks :-)

    I have tried a lot of different approaches to get the form/data into 1 request body, but it has so far not worked.

    Does anybody know of other components that can do this?

  5. #5
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, one step further i have manged to post a simple text file by formatting the request body into one send command like this:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim strResponse As String

    strResponse = WinHTTPPostRequest("http://appserver01/test/post.asp", "---------------------------7d52c539f044e")

    Response.Write(strResponse)
    Response.End()
    End Sub



    Function WinHTTPPostRequest(ByVal URL As String, ByVal Boundary As String)

    Dim http 'As New MSXML2.ServerXMLHTTP
    http = CreateObject("MSXML2.ServerXMLHTTP")
    http.open("POST", URL, False, "ingvar", "ingvar")


    http.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + Boundary)

    http.Send("" & _
    "-----------------------------7d52c539f044e" & vbCrLf & _
    "Content-Disposition: form-data; name=""dir""" & vbCrLf & vbCrLf & _
    "/hd6/fullpress/Webnative/Bico+Test/Uploaded/" & vbCrLf & _
    "-----------------------------7d52c539f044e" & vbCrLf & _
    "Content-Disposition: form-data; name=""filedata""; filename=""C:\b.txt""" & vbCrLf & _
    "Content-Type: text/plain" & vbCrLf & vbCrLf & _
    "This is a file." & vbCrLf & _
    "It has two lines." & vbCrLf & _
    "-----------------------------7d52c539f044e" & vbCrLf & _
    "Content-Disposition: form-data; name=""button""" & vbCrLf & vbCrLf & _
    "Last(opp)" & vbCrLf & _
    "-----------------------------7d52c539f044e--")





    'Get a result of the script which has received upload

    WinHTTPPostRequest = http.responseText
    End Function


    But now the problem is reading and encoding the image/files into the right format. Anybody know how this can be done? the file is stored localy on the IIS server.

  6. #6
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you send the other form params (file name etc) through querystring leaving the form available for the image?

    Code:
        xmlhttp.Open("POST", "BinaryStream.asp?filename=" + filname, false);
        xmlhttp.setRequestHeader("Content-Length", adoStream.Size);
        xmlhttp.send(adoStream.Read(adoStream.Size));
        alert(xmlhttp.responseText);
    Just a thought.

    (pinched from http://builder.com.com/5100-31-5078105.html)


Bookmarks

Posting Permissions

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