|
Home > Archive > IIS ASP > June 2007 > Upload file without user interaction in vba
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Upload file without user interaction in vba
|
|
| google.com@motix.com 2007-06-23, 1:23 pm |
| Hi there!
I've been digging around looking for a sample on how to upload a file
without user action. I found the following article covering the area:
http://www.motobit.com/tips/detpg_uploadvbaie/
It describes the vba code required to handle a very simple upload
form:
<Form Action=http://127.0.0.30/util/up/free/upload.asp
Method=Post ENCTYPE="multipart/form-data">
<Input Type=File Name=FileField>
<Input Type=Submit>
</Form>
And then the VBA comes here:
'Upload file using input type=file
Sub UploadFile(DestURL As String, FileName As String, _
Optional ByVal FieldName As String = "File")
Dim sFormData As String, d As String
'Boundary of fields.
'Be sure this string is Not In the source file
Const Boundary As String =
"---------------------------0123456789012"
'Get source file As a string.
sFormData = GetFile(FileName)
'Build source form with file contents
d = "--" + Boundary + vbCrLf
d = d + "Content-Disposition: form-data; name=""" + FieldName +
""";"
d = d + " filename=""" + FileName + """" + vbCrLf
d = d + "Content-Type: application/upload" + vbCrLf + vbCrLf
d = d + sFormData
d = d + vbCrLf + "--" + Boundary + "--" + vbCrLf
'Post the data To the destination URL
IEPostStringRequest DestURL, d, Boundary
End Sub
My problem is that my form looks like this:
<form action="upload.asp?
action=upload&type=product&item=pic1&element=&id=3170&w=1000&h=1000&maxw=200&maxh=5000"
method="post" name="upload" enctype="multipart/form-data">
<input type="hidden" name="type" value="product">
<input type="hidden" name="item" value="pic1">
<input type="hidden" name="element" value="">
<input type="hidden" name="id" value="3170">
<input type="hidden" name="w" value="1000">
<input type="hidden" name="h" value="1000">
<input type="file" name="picture" size="28">
<input type="submit" value=" upload "">
</form>
So how do I modify the above UploadFile sub, so that it includes all
the fields in the form?
Any help appreciated, because I have to upload 1000+ files 8-()
So any suggestions??
/hco
| |
| Dave Anderson 2007-06-25, 1:20 pm |
| google.com@motix.com wrote:
> <Form Action=http://127.0.0.30/util/up/free/upload.asp
> Method=Post ENCTYPE="multipart/form-data">
> <Input Type=File Name=FileField>
> <Input Type=Submit>
> </Form>
>
> And then the VBA comes here:
>
> 'Upload file using input type=file ...
I find it highly unlikely you are using VBA in ASP. You probably mean
VBScript.
> ...how do I modify the above UploadFile sub, so that it
> includes all the fields in the form?
1. Be prepared to parse *all* of the regions to discover the
non-file form data
2. Use a component
3. Use some other technology, like ASP.NET
--
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
| |
| hco@giving.dk 2007-06-25, 7:20 pm |
| Hi Dave
It is actually VBA, but that is besides the point.
I'm not looking for the asp code to recieve the posted form, but the
code to mimic the post of the form to the server.
In other words, my problem is how to build the sourceform so that it
includes the filestream AND the other fields on the form. So how do I
modify the "build" part below, so it includes the fields on the form
i'm trying to post?
'Build source form with file contents
d = "--" + Boundary + vbCrLf
d = d + "Content-Disposition: form-data; name=""" + FieldName +
""";"
d = d + " filename=""" + FileName + """" + vbCrLf
d = d + "Content-Type: application/upload" + vbCrLf + vbCrLf
d = d + sFormData
d = d + vbCrLf + "--" + Boundary + "--" + vbCrLf
I'm not sure where my question belongs, so If you have any suggestions
for a better place to ask, please let me know ;-)
/hco
| |
| Dave Anderson 2007-06-26, 1:19 pm |
| hco@giving.dk wrote:
> It is actually VBA, but that is besides the point.
>
> I'm not looking for the asp code to recieve the posted form,
> but the code to mimic the post of the form to the server.
Sorry. You can probably understand why I thought that your use of
<form action=path/upload.asp> suggests an ASP solution is sought.
^^^^^^^^^^
> In other words, my problem is how to build the sourceform so
> that it includes the filestream AND the other fields on the
> form. So how do I modify the "build" part below, so it includes
> the fields on the form i'm trying to post?
As I said, parse all of the regions. I cannot overstate the value of the
LiveHTTPHeaders extension for Firefox. Using a test form with three hidden
inputs and a file input, I was able to grab the entire request, including
the following:
Content-Type: multipart/form-data;
boundary=---------------------------29227157615760
Content-Length: 39804
-----------------------------29227157615760
Content-Disposition: form-data; name="Hidden1"
ValueOfHidden1
-----------------------------29227157615760
Content-Disposition: form-data; name="Hidden2"
ValueOfHidden2
-----------------------------29227157615760
Content-Disposition: form-data; name="Hidden3"
ValueOfHidden3
-----------------------------29227157615760
Content-Disposition: form-data; name="File1"; filename="135de8c6.jpg"
Content-Type: image/jpeg
{encoded binary data}
-----------------------------29227157615760--
So it seems to me you want to discover the region delimiter (or boundary)
and use it to define the regions corresponding to each input. Then start
parsing the regions. I have no doubt it will take work, but the above
example should give you something to work from.
--
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
| |
| hco@giving.dk 2007-06-27, 7:22 am |
| Hi Dave,
Thanks a lot! I think the http header thing will give me the
information I need to be able to construct the form.
I'll get back when i figure out how to construct the formdata.
/hc
|
|
|
|
|