4

This question has been asked many times by others in some form or another but most remained unanswered or the given answer is "Use C#, duh!", which incidentally, is a non-answer. ;-)

I want to upload a zip file to a web server via VBA. The server side code already exists and works well; it accepts zip files via manual form upload and does something with the contents of the zip file.

The theory is, I plan to transform the binary contents of the zip file into a HTTP request string and send it to the server using some methods from the WinHTTP library. If everything goes well the server side script (in Perl) shouldn't be able to tell whether the file came from VBA or a browser and continue working normally.

However, transmogrifying the zip file to a HTTP request string doesn't seem to be very straight forward.

Searching online seems to indicate there exists 3 common strategies:

Method 1: WinHTTP and manual encoding of binary to HTTP request string

  • Involves opening the file in binary mode and manually applying some encoding voodoo to change the binary stream into a HTTP request string and send it on its way using WinHTTP. Scary amount of code.

Method 2: WinHTTP

  • Involves using the ADODB.Stream. Less than ten lines of code.

Method 3: Automate IE via SendKeys

  • There's only one word to describe this hack : Yuck! And probably will break in future version of IE, if not already. Less than ten lines of code. Security risk.

I leaning towards Method 2, however, documentation is thin, code examples rare, and there's no certainty that it works. Most code examples are incomplete and often have comments that say they don't work. Does this method actually work?

Method 1 is next in line.

Method 3 Please, no! (Rather use C# if it comes to that. Love C#, just the requirements only permit VBA)

Anyone has any good examples on how to accomplish this task?

1

1 Answer 1

3

After a horrific volume of experimentation with all your methods above (and more), I'm using what pretty much amounts to your "Method 1" - I'm using item (2) from http://www.motobit.com/tips/detpg_post-binary-data-url/, but with the following assignment:

 Set http = CreateObject("WinHttp.WinHttprequest.5.1")

... instead of the one suggested in that code (the code is a little elderly, I think). It is not perfect, though - for example, I've been so far unable to get it working on an old Windows XP machine I had (works ok on Win7).

Sign up to request clarification or add additional context in comments.

7 Comments

@GeneQ Could you help me with posting a file using VBA?
@user793468 I'm rushing to meet a deadline. Give a couple of days and I'll post the code.
Are a couple of days over now?
Yes, would be great to hear how this was done... Been trying various things for a few days now, to no avail!
Agreed - be great to know how you achieved this
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.