PDA

View Full Version : Solved: HTTP POST for Input type=FILE



stanl
09-24-2006, 10:05 AM
A friend (he wrote the 802.1 standard for IBM) challenged me to write script code to complete an HTTP POST from

https://www.pdfonline.com/convert_pdf.asp

assuming I wanted to convert an excel file to a PDF and email it, a POST would look something like



cURL = "<A href="https://www.pdfonline.com/scripts/processfiles.asp?upfile=" & xlfile & "&e_mail=" & email & "&output=" &">https://www.pdfonline.com/scripts/processfiles.asp?upfile=" & xlfile & "&e_mail=" & email & "&output=" & outputfile

'then post with MSXML, xStandard or whatever



However, the input file is type=FILE in the HTML and it appears it cannot be automated w/out direct user action. If you were to script it with the IE Application Object, you would still run into a snag as well. Still, it does post and there has to be a way around embedding a valid input file. I'm just :banghead:

Stan

stanl
09-24-2006, 02:26 PM
Aaargghh! the code /code blocks threw in some misleading info. To simplify:

I want to post 3 vars

upfile - and excel workbook
e_mail - valid address to send converted PDF to
output - name of PDF file (no extension)

I have tried this with both MSXML2.HTTP and XStandard.Http - setting all sorts of requestheaders i.e.

oHTTP.AddRequestHeader("Content-Type", "multipart/form-data, boundary=AaB03x")
oHTTP.AddRequestHeader("Content-Type", "application/x-www-form-urlencoded")
oHTTP.AddRequestHeader("contenttype", "multipart/form-data")
oHTTP.AddRequestHeader("enctype", "multipart/form-data")
oHTTP.AddRequestHeader("postmode", "multipart form")

but the POSTS are rejected. I don't really intend to use this site for POSTS as I can convert and email docs locally, but I would like to make it work one time:ipray:

stanl
09-25-2006, 02:43 PM
figured it out.

mvidas
09-25-2006, 04:11 PM
do share!
I tried for a while a couple weeks ago on something just like this and ended up giving up. id love to see what you ended up with, see if i can adapt something similar
ok after reading more it was a bit different (this was uploading a file using xmlhttp to a network server) but im still curious.. :)

stanl
09-26-2006, 05:26 AM
ok after reading more it was a bit different (this was uploading a file using xmlhttp to a network server) but im still curious.. :)

I'm confused. Were you looking to upload a file to a server directory, only using HTTP rather than FTP - or, uploading files and other fields in response to a web form? If the former, simply package as an ADODB.Stream, read into the XMLDOM and POST. If the latter (which frustrated me), I ended up using a Winsock wrapper dll which poked values into a binary buffer then sent the buffer to the URL; but out of sheer stubborness:motz2: I want to see if I can build a similar buffer as an ADODB Stream Object and use HTTP Post - and at that point I will post code. The good news is what started out as a 'bet' has tweaked curiosity in my boss who doesn't want to license ADOBE for multiple workstations to convert 'Personal Excel Budgets' to PDF, and sees PDFOnline as a free alternative.

Stan

mvidas
09-26-2006, 06:34 AM
That is interesting, I've tried to do the same but as the .value property is read-only I decided to use sendkeys to do it: Set IE = New InternetExplorer
IE.Visible = True
IE.Navigate2 vURL
Do While IE.readyState <> 4
DoEvents
Loop
With IE.Document.Forms(0)
DoEvents
SetForegroundWindow IE.hwnd
DoEvents
.Item("File1").Focus
DoEvents
SendKeys "C:\filename.xls", True
.Submit
End With
For my other thing, converting to an adodb.stream didn't work in his case, and as far as I know he never got it working (never figured out why he couldnt use ftp but that was what he said)

stanl
09-26-2006, 07:16 AM
well, there are problems w/security and credentials using IE (and bugs too!).

To simply upload a file as a Stream, use the XMLHTTP 'PUT' [assuming the web server accepts PUT]... below is really simplified, no error checking or checking for the HTTP status, and for binary files



file = "c:\test\myfile.xls"
URL = "http://mysite/mysubdir/myfile.xls"
oS = CreateObject("ADODB.STREAM")
oS.Type=1 'binary
oS.Open
oS.LoadFromFile file
oHTTP = CreateObject("MSXML2.HTTP")
oHTTP.Open "PUT", URL, false
oHTTP.Send oS.Read
oS.Close
oS= Nothing
oHTTP=Nothing


Stan

mvidas
09-26-2006, 07:38 AM
Do you have an account over at EE? Take a look at http://www.experts-exchange.com/Applications/MS_Office/Excel/Q_21965670.html#17384060 to see where I got to (and the original question), maybe you can help to get it to work?

stanl
09-27-2006, 04:13 AM
Do you have an account over at EE? Take a look at http://www.experts-exchange.com/Applications/MS_Office/Excel/Q_21965670.html#17384060 to see where I got to (and the original question), maybe you can help to get it to work?

Just a S.W.A.G. but I believe that code, or what I posted only works with IIS. I just tried a PUT with WinHttp.WinHttpRequest.5.1 and a workbook on a password site (so you use setcredentials() ). The response status was 501 - Not Implemented, although I was able to use Shell.Application and copyhere() to upload the file. Wish I could be more help.

Stan

mvidas
09-27-2006, 06:29 AM
Wish I could be more help.That is exactly how I feel! But when the asker doesn't explain why there are such narrow restrictions like that, that explanation usually explains why the 'should work' doesnt work.

stanl
09-28-2006, 09:10 AM
That is exactly how I feel! But when the asker doesn't explain why there are such narrow restrictions like that, that explanation usually explains why the 'should work' doesnt work.

I'm not giving up on it. I use Streams a lot in script and increasingly run into situation where the InternetExplorer.Application Object is not an option, or users would prefer HTTP Requests and just keep a browser out of the picture.