Mimic Input Type=File server to server

G

garbagecatcher

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
 
A

Aaron Bertrand - MVP

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?
 
G

garbagecatcher

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
 
A

Aaron Bertrand - MVP

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
 
G

garbagecatcher

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
 
A

Aaron Bertrand - MVP

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
%>
 
G

garbagecatcher

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top