Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Upload file without user interaction - VBA

Hi !

I would like to upload files to a Webserver, but the problem is that
the server only accepts uploads via FORM. The form looks like this:

<form action="upload.asp?
action=upload&type=product&item=pic1&element=&id=3 170&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 my question is, how do I create a sub in vba/excel, which looks
like this:

public sub UploadFile( FileToUpload as string)

The sub should read the file FileToUpload, and post it on the
webserver using the form.

Any help appreciated, because I have to upload 1000+ files 8-()


/hco

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Upload file without user interaction - VBA

I'm not an expert on this, but I think you arre a little confused in what you
are asking for. I think you need to transfer a file, not send the text data
line by line. You probably need to use FTP, not HTTP.

FTP is File Transfer Protocol. HTTP is Hyper-Text Transfer Protocol. HTTP
sends the text character inside a file and displays the text to a screen.
FTP just send the files between two computers but doesn't display the text.

Your posting first says I want to upload files which is FTP.

" wrote:

Hi !

I would like to upload files to a Webserver, but the problem is that
the server only accepts uploads via FORM. The form looks like this:

<form action="upload.asp?
action=upload&type=product&item=pic1&element=&id=3 170&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 my question is, how do I create a sub in vba/excel, which looks
like this:

public sub UploadFile( FileToUpload as string)

The sub should read the file FileToUpload, and post it on the
webserver using the form.

Any help appreciated, because I have to upload 1000+ files 8-()


/hco


  #3   Report Post  
Posted to microsoft.public.excel.programming
Tim Tim is offline
external usenet poster
 
Posts: 145
Default Upload file without user interaction - VBA

The OP does not seem confused to me - requirements seem clear that the only
available method is using an HTTP form and the POST method. The question is
then how to automate this process.

Never tried this, but one possibility might be to automate IE to upload the
files. The on sticking point may be that for obvious reasons the "file"
input element does not allow setting the value (path) through script: not
sure if this extends to automation from outside of IE.

Tim


"Joel" wrote in message
...
I'm not an expert on this, but I think you arre a little confused in what
you
are asking for. I think you need to transfer a file, not send the text
data
line by line. You probably need to use FTP, not HTTP.

FTP is File Transfer Protocol. HTTP is Hyper-Text Transfer Protocol. HTTP
sends the text character inside a file and displays the text to a screen.
FTP just send the files between two computers but doesn't display the
text.

Your posting first says I want to upload files which is FTP.

" wrote:

Hi !

I would like to upload files to a Webserver, but the problem is that
the server only accepts uploads via FORM. The form looks like this:

<form action="upload.asp?
action=upload&type=product&item=pic1&element=&id=3 170&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 my question is, how do I create a sub in vba/excel, which looks
like this:

public sub UploadFile( FileToUpload as string)

The sub should read the file FileToUpload, and post it on the
webserver using the form.

Any help appreciated, because I have to upload 1000+ files 8-()


/hco




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Upload file without user interaction - VBA

Excel may be the right tool for the job when it comes to saving the
file names you want to upload, but it's the wrong tool for the job
when it comes to posting those files to a url using http.

The right tool for the job would be H-P's LoadRunner application.
You'd open ViewGen, turn on the recorder, visit the form, upload a
file, edit the generated code to fetch file names from your Excel
Workbook, open the Controller, then create a task to upload all your
files.

You can download a test value and if it's a one shot deal go with
that.

If this happens on a regular basis, then LR might not be the tool for
the job because it has an expensive license.

In anycase, the fact that you aren't using ftp or aren't mounting a
shared drive suggests that either you're a spammer or you don't know
what you're doing.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Upload file without user interaction - VBA

Hi there!

I've been digging around and 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 he

'******************* upload - begin
'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

'sends URL encoded form data To the URL using IE
Sub IEPostStringRequest(URL As String, FormData As String, Boundary As
String)
'Create InternetExplorer
Dim WebBrowser: Set WebBrowser =
CreateObject("InternetExplorer.Application")

'You can uncoment Next line To see form results
'WebBrowser.Visible = True

'Send the form data To URL As POST request
Dim bFormData() As Byte
ReDim bFormData(Len(FormData) - 1)
bFormData = StrConv(FormData, vbFromUnicode)

WebBrowser.Navigate URL, , , bFormData, _
"Content-Type: multipart/form-data; boundary=" + Boundary + vbCrLf

Do While WebBrowser.busy
' Sleep 100
DoEvents
Loop
WebBrowser.Quit
End Sub

'read binary file As a string value
Function GetFile(FileName As String) As String
Dim FileContents() As Byte, FileNumber As Integer
ReDim FileContents(FileLen(FileName) - 1)
FileNumber = FreeFile
Open FileName For Binary As FileNumber
Get FileNumber, , FileContents
Close FileNumber
GetFile = StrConv(FileContents, vbUnicode)
End Function
'******************* upload - end


It almost works, but I stil haven't found out how to pass all the
parameters on the form, as I've stated in my initial post.

So, I also think excel is the tool, but I just need some extra
tweaking ;-)

So any suggestions??

/hco




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Upload file without user interaction - VBA

See if you can access Explorer's document object and set the form
parameters with the syntax:

document.myForm.myParameter ="myValue"

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Upload file without user interaction - VBA

That won't do the job, because the above code is actually mimicking
the stream send from the browser to the webserver.
In other words, I never actually load the form. Only submit the data.

No, I think the secret lies in the Encoding in the UploadFile(DestURL
As String, FileName As String,...) sub.
My problem is that I just don't know how to encode other fields into
the formdata.

But maybe this is more like a ASP question and not VBA question. Any
good groups for that??

/hco

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How Email does not need user interaction ? Koulla Excel Discussion (Misc queries) 4 October 15th 08 02:41 PM
user interaction to select a sheet mark Excel Programming 5 May 29th 07 03:11 AM
programmatically add Outlook control for user interaction/feedback Loane Sharp[_2_] Excel Programming 0 May 13th 06 09:24 AM
Separating Business Logic from User Interaction (Userforms) chatterbox Excel Programming 0 November 24th 05 11:38 AM
Modeless form for user interaction Arne[_2_] Excel Programming 6 July 15th 03 02:22 PM


All times are GMT +1. The time now is 09:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"