VB ActiveX to upload a file using HTTP Post 
Author Message
 VB ActiveX to upload a file using HTTP Post
Hello,

I would like to make an VB ActiveX to upload file from IE to my server,
using HTTP POST upload. I have got the following example but it is not
working. Does anybody know how to do something like that? How to get
XMLHTTP26?

Many thanks,
Sebastien

Option Explicit
'This code uploads a file to an ASP script using http post
'You need to add a reference to Microsoft XML, V26 to the project.
'Get this from http://www.*-*-*.com/

Private Sub cmdSubmit_Click()
Dim strText As String
Dim strBody As String
Dim strFileName As String
Dim oHttp As XMLHTTP26

'make use of the XMLHTTPRequest object contained in msxml.dll
Set oHttp = New XMLHTTP26
'enter your data
strText = InputBox("Text:", "Upload a file", "<h1>Test2</h1>")
strFileName = InputBox("File Name:", "Upload a file", "dummy.htm")
'fire of an http request
oHttp.open "POST", "http://www.../upload.asp", False
oHttp.setRequestHeader "Content-Type", "multipart/form-data,
boundary=AaB03x"
'assemble the body. send one field and one file
strBody = _
   "--AaB03x" & vbCrLf & _
   "content-disposition: form-data; name=""field1""" & vbCrLf & vbCrLf & _
   "test field" & vbCrLf & _
   "--AaB03x" & vbCrLf & _
   "content-disposition: form-data; name=""xyz""; filename=""" & strFileName
& """" & vbCrLf & _
   "Content-Type: text/plain" & vbCrLf & vbCrLf & _
   strText & vbCrLf & _
   "--AaB03x--"
'send it
oHttp.send strBody
'check the feedback
Debug.Print oHttp.responseText

End Sub



Sat, 10 Aug 2002 03:00:00 GMT  
 VB ActiveX to upload a file using HTTP Post
if i remember well there was a subtle bug about open method, try not to pass
strings directly , put them in a variable string and pass the variable.
I hope it makes a difference
--
Enrico Sabbadin

http://sabbadin.tripod.com
MTS FAQ: http://sabbadin.tripod.com/mts_faq.htm
---------------------------------------------------


Quote:
> Hello,

> I would like to make an VB ActiveX to upload file from IE to my server,
> using HTTP POST upload. I have got the following example but it is not
> working. Does anybody know how to do something like that? How to get
> XMLHTTP26?

> Many thanks,
> Sebastien

> Option Explicit
> 'This code uploads a file to an ASP script using http post
> 'You need to add a reference to Microsoft XML, V26 to the project.
> 'Get this from http://www.microsoft.com/xml

> Private Sub cmdSubmit_Click()
> Dim strText As String
> Dim strBody As String
> Dim strFileName As String
> Dim oHttp As XMLHTTP26

> 'make use of the XMLHTTPRequest object contained in msxml.dll
> Set oHttp = New XMLHTTP26
> 'enter your data
> strText = InputBox("Text:", "Upload a file", "<h1>Test2</h1>")
> strFileName = InputBox("File Name:", "Upload a file", "dummy.htm")
> 'fire of an http request
> oHttp.open "POST", "http://www.../upload.asp", False
> oHttp.setRequestHeader "Content-Type", "multipart/form-data,
> boundary=AaB03x"
> 'assemble the body. send one field and one file
> strBody = _
>    "--AaB03x" & vbCrLf & _
>    "content-disposition: form-data; name=""field1""" & vbCrLf & vbCrLf & _
>    "test field" & vbCrLf & _
>    "--AaB03x" & vbCrLf & _
>    "content-disposition: form-data; name=""xyz""; filename=""" &
strFileName
> & """" & vbCrLf & _
>    "Content-Type: text/plain" & vbCrLf & vbCrLf & _
>    strText & vbCrLf & _
>    "--AaB03x--"
> 'send it
> oHttp.send strBody
> 'check the feedback
> Debug.Print oHttp.responseText

> End Sub



Sun, 11 Aug 2002 03:00:00 GMT  
 VB ActiveX to upload a file using HTTP Post
Well if you are using the cpshost.dll in the following manner in http:

    <form

action="http://MyNTServer/scripts/cpshost.dll?PUBLISH?http://MyNTServer/MyTe
stProject/ProcFile.asp"
       encType="multipart/form-data" id="form2" method="post" name="form2"
      <input type="hidden" name="TargetURL"
      value="http://MyNTServer/MyTestProject/upload/<%=varPath%>">
        ....
   </form>

then you have to prepare the whole thing in the following way:

- Be sure your upload directory has the correct rights (writable, no
execution, not readable, ...) on directory and file basis.
- You have to add an entry inside the registry that allows anonymous logins
at you server, otherwise the upload will always fail. Adding this entry is
the key (I attach the Knowledge Base article in this RE).

Be aware: Allowing anonymous logins to your server may harm your system if
you are lazy setting the access rights in IIS an at the file system. If you
allow anonymous logins an there is an directory with write an execute
permission in IIS and the file system anybody can put an executable on your
system and start it !!!...

Attched: The Knowledge Base article: Article ID: Q179566
===============================================
For Microsoft Internet Information Server (IIS) 3.0:
1. Remove the authentication code from any .asp files involved with
   the upload process (for example, upload*.asp, repost.asp).

2. Set the TargetURL variable to a directory that IUSR_<machinename>
   has write access to.

3. Start In the .asp files involved with the upload process and open the
   following location in the registry:

      HKEY_LOCAL_MACHINE\Software\Microsoft\WebPost\Acceptors\CPSHost

4. Create a new REG_DWORD value named "AllowAnonymous" and set the value
   to "1" (both without the quotation marks).

5. Reboot the computer.
For Microsoft Internet Information Server (IIS) 4.0:
1. In the Microsoft Management Console (MMC), create a virtual root with
   write access permissions (as designated in the MMC).

2. Make sure that the Allow Anonymous option is enabled for the virtual
   root created, for the /Scripts directory, and for the Web root.

3. In the .asp files involved with the upload process, remove the
   authentication code.

4. Set the TargetURL variable in the Postinfo.asp and Upload.asp files
   to a directory that IUSR_<machinename> has write access to.

5. Start Regedt32.exe, and open the following location in the registry:
   HKEY_LOCAL_MACHINE\Software\Microsoft\WebPost\Acceptors\CPSHost

6. Create a new REG_DWORD value named "AllowAnonymous" and set the value
   to "1" (both without the quotation marks).

7. Reboot the computer.



Quote:
> Hello,

> I would like to make an VB ActiveX to upload file from IE to my server,
> using HTTP POST upload. I have got the following example but it is not
> working. Does anybody know how to do something like that? How to get
> XMLHTTP26?

> Many thanks,
> Sebastien

> Option Explicit
> 'This code uploads a file to an ASP script using http post
> 'You need to add a reference to Microsoft XML, V26 to the project.
> 'Get this from http://www.microsoft.com/xml

> Private Sub cmdSubmit_Click()
> Dim strText As String
> Dim strBody As String
> Dim strFileName As String
> Dim oHttp As XMLHTTP26

> 'make use of the XMLHTTPRequest object contained in msxml.dll
> Set oHttp = New XMLHTTP26
> 'enter your data
> strText = InputBox("Text:", "Upload a file", "<h1>Test2</h1>")
> strFileName = InputBox("File Name:", "Upload a file", "dummy.htm")
> 'fire of an http request
> oHttp.open "POST", "http://www.../upload.asp", False
> oHttp.setRequestHeader "Content-Type", "multipart/form-data,
> boundary=AaB03x"
> 'assemble the body. send one field and one file
> strBody = _
>    "--AaB03x" & vbCrLf & _
>    "content-disposition: form-data; name=""field1""" & vbCrLf & vbCrLf & _
>    "test field" & vbCrLf & _
>    "--AaB03x" & vbCrLf & _
>    "content-disposition: form-data; name=""xyz""; filename=""" &
strFileName
> & """" & vbCrLf & _
>    "Content-Type: text/plain" & vbCrLf & vbCrLf & _
>    strText & vbCrLf & _
>    "--AaB03x--"
> 'send it
> oHttp.send strBody
> 'check the feedback
> Debug.Print oHttp.responseText

> End Sub



Fri, 23 Aug 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. VB ActiveX to upload a file using HTTP Post

2. File upload from VB 6 to ASP file using http form post

3. File Upload Using HTTP Post w/INET Control

4. Datei Upload per HTTP / File upload via HTTP

5. inet http post file upload problem

6. Uploading File with HTTP POST useing the VB5.0(sp3) internet transfer Control

7. Uploading File with HTTP POST

8. HOW Do U Upload a File as part of a FORM POST using VB.NET

9. Multipart MIME/HTTP Upload - Post

10. How to upload binary files using HTTP

11. How to Upload Binary file using HTTP

12. Uploading a file using Inet control with HTTP

 

 
Powered by phpBB® Forum Software