Consulting

Results 1 to 11 of 11

Thread: Solved: HTTP POST for Input type=FILE

  1. #1
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location

    Solved: HTTP POST for Input type=FILE

    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

    Stan

  2. #2
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    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

  3. #3
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    figured it out.

  4. #4
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    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..

  5. #5
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by mvidas
    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 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

  6. #6
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    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:[vba] 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[/vba]
    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)

  7. #7
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    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

  8. #8
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Do you have an account over at EE? Take a look at http://www.experts-exchange.com/Appl....html#17384060 to see where I got to (and the original question), maybe you can help to get it to work?

  9. #9
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by mvidas
    Do you have an account over at EE? Take a look at http://www.experts-exchange.com/Appl....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

  10. #10
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    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.

  11. #11
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by mvidas
    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.

Posting Permissions

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