Mimic Input Type=File server to server

Discussion in 'ASP General' started by garbagecatcher, Sep 9, 2003.

  1. Hello,

    here's my problem:

    On my web server I generate a file, I need to send this
    file to a different web server.

    I have no control over the other web server.

    The only way they accept files is through input type="file"

    Since I generate the file on my server, I'd like to post
    this directly to their server without the user having to
    download the file from my server, and go to the other
    server to upload it.

    Right now I'm using XMLHTTP (post) to login to the other
    webserver, this works fine:

    Response.Buffer = True
    Dim objXMLHTTP, xml
    Set xml = Server.CreateObject("Microsoft.XMLHTTP")
    xml.Open "POST", "https://domain.com/login.asp", False
    xml.setRequestHeader "lastCached", now()
    xml.setRequestHeader "Content-Type", "application/x-www-
    form-urlencoded"
    xml.Send "username=username&password=password"
    Response.Write xml.responseText
    Set xml = Nothing


    Can I use this same process (XMLHTTP) to read and post a
    file? What is the syntax for that? I'm not normally an asp
    programmer so any detailed instructions would really be
    appreciated!

    Thanks
     
    garbagecatcher, Sep 9, 2003
    #1
    1. Advertising

  2. > On my web server I generate a file, I need to send this
    > file to a different web server.


    If it's within your network, you can use FileSystemObject and copy the file
    over \\servername\sharename\ or a mapped drive letter (see
    http://www.aspfaq.com/2168).

    > I have no control over the other web server.


    Ah. If it's outside of your network, you could use FTP (see
    http://www.aspfaq.com/2110).

    > Can I use this same process (XMLHTTP) to read and post a
    > file?


    I'd be very surprised. The construct of an upload is that the component (or
    script) sits on the server that controls and accepts the files it accepts.
    Imagine if you could just upload any arbitrary file to any server of your
    choosing?
     
    Aaron Bertrand - MVP, Sep 9, 2003
    #2
    1. Advertising

  3. Hey Aaron, thanks for the reply

    Unfortunately I cant FTP the information up there

    This is what it is like, lets say google has a form on
    their website located at...
    http://www.google.com/uploadstuff.html

    and that page looks like this:

    <form name="upload" action="upload.asp" method="post">
    <input type="file" name="uploadThisFile">
    <input type="submit">
    </form>

    A normal user can go to this url, browse for a file on
    their computer and upload it to google.

    I want my webserver to go to this url, and submit a file
    (from the webserver), as if it was using input type="file"

    Does this make sense? You can do this in cold fusion
    through the use of cfhttp, it would look like this:

    <cfhttp url="http://www.google.com/upload.asp"
    method="POST"
    resolveurl="false"
    throwonerror="no"
    timeout="15">
    <cfhttpparam
    type="FILE"
    name="IsPost"
    file="c:\path\myfile.jpg">
    </cfhttp>

    I'm trying to do that exact call, using ASP instead
     
    garbagecatcher, Sep 9, 2003
    #3
  4. > A normal user can go to this url, browse for a file on
    > their computer and upload it to google.


    And google also has a receiving web page, *on their server* that accepts and
    handles the file.

    Do you have such a web page on this web server you can't control?

    A
     
    Aaron Bertrand - MVP, Sep 9, 2003
    #4
  5. >Do you have such a web page on this web server you can't
    control?

    Exactily, and I just need to know how I can send a file
    through that form through my webserver. Is this possible
    with XMLHTTP?

    So to continue with this google concept. If google had a
    web page that had this content:

    http://www.google.com/uploadstuff.html
    <form name="upload" action="upload.asp" method="post">
    <input type="file" name="uploadThisFile">
    <input type="submit">
    </form>

    And you needed to submit files from your webserver to
    google, using that form. How would you do it? I think it
    can be done using something like this (code example
    below). I just don't know how to read and post the file:

    Response.Buffer = True
    Dim xml
    Set xml = Server.CreateObject("Microsoft.XMLHTTP")
    xml.Open "POST", "http://www.google.com/upload.asp", False
    xml.setRequestHeader "Content-Type", "application/x-www-
    form-urlencoded"
    xml.Send "uploadThisFile=" //I don't know how to read or
    post the file
    Set xml = Nothing
     
    garbagecatcher, Sep 9, 2003
    #5
  6. Never tried it, but maybe you could play with adodb.stream, e.g. something
    like this:

    <%
    set adoStream = CreateObject("ADODB.Stream")
    adoStream.mode = 3
    adoStream.type = 1
    adoStream.open
    adoStream.loadFromFile "c:\path\file.extension"
    data = adoStream.read(adoStream.size) ' may need set here?
    set adoStream = nothing

    Set xml = Server.CreateObject("Microsoft.XMLHTTP")
    xml.Open "POST", "http://www.google.com/upload.asp", False
    xml.setRequestHeader "Content-Type", "appl" & _
    "ication/x-www-form-urlencoded"
    xml.Send "uploadThisFile=" & data
    Set xml = Nothing
    %>






    "garbagecatcher" <> wrote in message
    news:03bf01c37706$12bc8640$...
    > >Do you have such a web page on this web server you can't

    > control?
    >
    > Exactily, and I just need to know how I can send a file
    > through that form through my webserver. Is this possible
    > with XMLHTTP?
    >
    > So to continue with this google concept. If google had a
    > web page that had this content:
    >
    > http://www.google.com/uploadstuff.html
    > <form name="upload" action="upload.asp" method="post">
    > <input type="file" name="uploadThisFile">
    > <input type="submit">
    > </form>
    >
    > And you needed to submit files from your webserver to
    > google, using that form. How would you do it? I think it
    > can be done using something like this (code example
    > below). I just don't know how to read and post the file:
    >
    > Response.Buffer = True
    > Dim xml
    > Set xml = Server.CreateObject("Microsoft.XMLHTTP")
    > xml.Open "POST", "http://www.google.com/upload.asp", False
    > xml.setRequestHeader "Content-Type", "application/x-www-
    > form-urlencoded"
    > xml.Send "uploadThisFile=" //I don't know how to read or
    > post the file
    > Set xml = Nothing
     
    Aaron Bertrand - MVP, Sep 9, 2003
    #6
  7. Hi,
    Please see 'Upload file using IE+ADO without user interaction - VBS '
    article at http://www.pstruh.cz/tips/detpg_uploadvbsie.htm. It let's you
    prepare document with multipart data to send a file to another server.

    Antonin

    "garbagecatcher" <> wrote in message
    news:015701c376f9$878ced00$...
    > Hello,
    >
    > here's my problem:
    >
    > On my web server I generate a file, I need to send this
    > file to a different web server.
    >
    > I have no control over the other web server.
    >
    > The only way they accept files is through input type="file"
    >
    > Since I generate the file on my server, I'd like to post
    > this directly to their server without the user having to
    > download the file from my server, and go to the other
    > server to upload it.
    >
    > Right now I'm using XMLHTTP (post) to login to the other
    > webserver, this works fine:
    >
    > Response.Buffer = True
    > Dim objXMLHTTP, xml
    > Set xml = Server.CreateObject("Microsoft.XMLHTTP")
    > xml.Open "POST", "https://domain.com/login.asp", False
    > xml.setRequestHeader "lastCached", now()
    > xml.setRequestHeader "Content-Type", "application/x-www-
    > form-urlencoded"
    > xml.Send "username=username&password=password"
    > Response.Write xml.responseText
    > Set xml = Nothing
    >
    >
    > Can I use this same process (XMLHTTP) to read and post a
    > file? What is the syntax for that? I'm not normally an asp
    > programmer so any detailed instructions would really be
    > appreciated!
    >
    > Thanks
     
    Antonin Foller, Sep 10, 2003
    #7
  8. Thank you for all your suggestions,

    It seems like it is the right track to use ADODB.Stream
    and MSXML2.ServerXMLHTTP.4.0, but it still doesn't work
    for me.

    There are a few things I should mention.

    The form that has the input type="file" also has another
    section that is required.

    So it is like this:
    (mytical form at http://www.google.com/uploadstuff.html)
    <form action="upload.asp">
    <input type="text" name="textName">Name
    <input type="file" name="fileName">
    </form>


    set adoStream = CreateObject("ADODB.Stream")
    adoStream.mode = 3
    adoStream.type = 1
    adoStream.open
    adoStream.loadFromFile "File.txt"
    data = adoStream.read(adoStream.size) ' may need set here?

    Set xml = Nothing
    Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
    Response.Buffer = True
    xml.Open "POST", "http://www.google.com/upload.asp?
    inputName=File", False
    xml.setRequestHeader "lastCached", now()
    xml.setRequestHeader "Content-Type", "application/x-www-
    form-urlencoded"
    xml.Send data
    Response.write xml.responseText
    Set xml = Nothing

    ------
    Problems:
    I don't see any way to give the data a name,
    like "fileName", I think if I can do that I will be golden!

    If i try:
    xml.Send "fileName=" & data

    I get a conversion error.

    Any more suggestions?

    I also found this article, but it seems to have the same
    info
    http://www.perfectxml.com/msxmlAnswers.asp?Row_ID=60
     
    garbagecatcher, Sep 10, 2003
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Foster

    Perl script to mimic uniq

    Martin Foster, Jan 30, 2004, in forum: Perl
    Replies:
    9
    Views:
    713
    Aaron Sherman
    Feb 5, 2004
  2. Do
    Replies:
    1
    Views:
    3,003
    Ken Cox [Microsoft MVP]
    Nov 23, 2003
  3. Roberto
    Replies:
    3
    Views:
    312
  4. Schüle Daniel

    mimic File.open pattern

    Schüle Daniel, Jul 30, 2006, in forum: Ruby
    Replies:
    5
    Views:
    135
    Schüle Daniel
    Jul 30, 2006
  5. Replies:
    6
    Views:
    254
    The Natural Philosopher
    May 31, 2009
Loading...

Share This Page