Professional Web Applications Themes

Mimic Input Type=File server to server - ASP

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

  1. #1

    Default Mimic Input Type=File server to server

    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 Guest

  2. #2

    Default Re: Mimic Input Type=File server to server

    > 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
    [url]http://www.aspfaq.com/2168[/url]).
    > I have no control over the other web server.
    Ah. If it's outside of your network, you could use FTP (see
    [url]http://www.aspfaq.com/2110[/url]).
    > 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 Guest

  3. #3

    Default Re: Mimic Input Type=File server to server

    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...
    [url]http://www.google.com/uploadstuff.html[/url]

    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 Guest

  4. #4

    Default Re: Mimic Input Type=File server to server

    > 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 Guest

  5. #5

    Default Re: Mimic Input Type=File server to server

    >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:

    [url]http://www.google.com/uploadstuff.html[/url]
    <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 Guest

  6. #6

    Default Re: Mimic Input Type=File server to server

    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" <garbagecatcherhotmail.com> wrote in message
    news:03bf01c37706$12bc8640$a301280aphx.gbl...
    > >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:
    >
    > [url]http://www.google.com/uploadstuff.html[/url]
    > <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 Guest

  7. #7

    Default Re: Mimic Input Type=File server to server

    Hi,
    Please see 'Upload file using IE+ADO without user interaction - VBS '
    article at [url]http://www.pstruh.cz/tips/detpg_uploadvbsie.htm[/url]. It let's you
    prepare doent with multipart data to send a file to another server.

    Antonin

    "garbagecatcher" <garbagecatcherhotmail.com> wrote in message
    news:015701c376f9$878ced00$a401280aphx.gbl...
    > 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 Guest

  8. #8

    Default Mimic Input Type=File server to server

    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 [url]http://www.google.com/uploadstuff.html[/url])
    <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
    [url]http://www.perfectxml.com/msxmlAnswers.asp?Row_ID=60[/url]

    garbagecatcher Guest

  9. #9

    Default Re: Mimic Input Type=File server to server

    There are no time stamps on posts, so I have no idea how old this thread is. Did this by chance get resolved with working code? We have the exact same scenario going on now where we need to take a file that is on our local web server, and submit it to another web server at our client's location.
    Bryan Fritchie is offline Junior Member
    Join Date
    Jun 2011
    Posts
    1

Similar Threads

  1. Write input text to server file.
    By synergy46 in forum Macromedia Flash Data Integration
    Replies: 0
    Last Post: June 29th, 09:44 PM
  2. Replies: 3
    Last Post: October 18th, 06:56 AM
  3. Replies: 2
    Last Post: October 16th, 08:29 AM
  4. reading the input type=file tag with ie6 in asp
    By Joel Goldstick in forum ASP
    Replies: 1
    Last Post: September 25th, 10:49 PM
  5. input type=file
    By Paul Moffitt in forum ASP
    Replies: 4
    Last Post: August 28th, 06:40 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139