Page 2 of 2 FirstFirst 12
Results 41 to 66 of 66

Thread: Winsock: HTTP File Upload

  1. #41

    Thread Starter
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Winsock: HTTP File Upload

    It probably has something to do with the code page or character set used in Visual Basic. As I don't have a Chinese OS, I cannot test this. Your OS most probably uses Unicode (an encoding format not supported via HTTP).

    For text files, the majority of characters will be within the extended ASCII range (<255). I would imagine what is happening with binary files, is that as each character is represented by 2 bytes instead of 1, the high order byte is being truncated and hence lost.

    Have a look at this unicode FAQ posted by Merri.

    http://www.vbforums.com/showthread.php?t=365738

    In any case, I recommend that you convert all the strings to UTF-8 (the extended ASCII equivalent of Unicode) as this will ensure characters with codes above 256 are handled properly by the server.
    My recommendation is that you convert the data to UTF-8 encoding.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  2. #42
    New Member
    Join Date
    Aug 2006
    Location
    Mumbai
    Posts
    7

    Re: Winsock: HTTP File Upload

    Umm.. thanks for the explaination ...tried ...but with little luck
    Anything you wish me to try ? me stuck with this issue.

  3. #43
    New Member
    Join Date
    Nov 2006
    Posts
    10

    Post Winsock: how to upload multiple file using HTTP File Upload

    Hello
    Your code is Working very well.
    but now problem is that if i am Upload Single File It works Fine.
    But If i am try to Upload Multiple file it only uploads the First one.

    What I am doing is Call Cmd_upload Multiple time to Upload Multiple File. Whether it is right way or not..


    plz Help Me

  4. #44
    New Member
    Join Date
    Apr 2007
    Posts
    3

    Re: Winsock: HTTP File Upload

    Could you help me make a program, which automatically takes a screenshot of the active window when hitting F11, then submits it to my own image uploader page and returns the url shown on it?

    Regards,

    Clooth

  5. #45
    New Member
    Join Date
    Jun 2007
    Posts
    2

    Re: Winsock: HTTP File Upload

    Hi people,

    I already try the code and modified to fit my requirements.

    It work very well thanks to visualAd, but i have a little problem with the control winsockt, i duno how to ensure the control propely connect or disconect.

    It works great, but at some point the control dosent disconect or conecct and the code hang up, into an infinite cilce, in part 1 or part 2 (listed in the code above)

    i already try a lot of things, and of course i have 2 event's that change the flags for conected or disconected, on sckts events.

    i hope somebody can help to figure out this issue.

    Sorry for my very bad english.

    this is part of the code:

    lngIndice = 1
    While lngIndice <= lngCantidadArchivos

    ' if the conection is un use, wait until disconected
    ' (part 1 when the control don't disconnect propely)
    If Not mbolSckConectado Then

    ' Here i set variables for teh file
    strNombreArchivo = arsNumerosOV(lngIndice) & ".PDF"
    strArchivoPDF = strDirectorio & strNombreArchivo

    ' here i get the contents of file
    strContenidoArchivo=dfObtenerContenidoArchivo(strArchivoPDF)

    ' here i biuld the HTTP request
    strRequisicionHTTP = dfHTTPRequest(strContenidoArchivo, udtURLDestino, strNombreArchivo, strNombreArchivo, strTipoMIME)

    ' here i conecct to the server, and wait until conected
    ' (part 2 when the control don't connect propely)
    sckSitioWeb.Connect
    While Not mbolSckConectado
    DoEvents
    Wend

    ' here i send the HTTP request
    sckSitioWeb.SendData strRequisicionHTTP

    ' here i susspend the program ejecution 2 sec
    dfSuspenderEjecucion 2

    End If

    Wend

  6. #46
    New Member
    Join Date
    Nov 2006
    Posts
    11

    Re: Winsock: HTTP File Upload

    Hi Guys,

    I would also would like to thank you for the great code!

    As said before me, I also uploaded files successfully when the default language is set to English, but failed when I changed the default language to Chinese.
    Using snifer, I found out that the the HTTP packet sent by winsock.senddata is corrupted, and I dont understand why. The packet length was different when I used English and Chiense as default lanaguage, however the length of strHttp (in the line WinsockUpload.SendData strHttp) was identical in both scenarios.

    Someone found a workaround/solution for that case?

    Many thanks in advance

  7. #47
    New Member
    Join Date
    Jul 2007
    Posts
    1

    Re: Winsock: HTTP File Upload

    It seems to work great when sending it to the codedv.com site listed in the source code. When I try to send it to my own site I get a 403 error. I can upload files using a standard web form page, but I really need to be able to do it from VB and I was hoping this would be the solution.

    Any suggestions?

  8. #48
    New Member
    Join Date
    Jul 2007
    Posts
    1

    Re: Winsock: HTTP File Upload

    Please please please
    Anyone here can convert this code to use Microsoft Internet Controls WebBrowser control ??..instead WinSock..
    Please
    WebBrowser control in Microsoft Internet Controls includes function Navigate and Navigate2, which can send navigate and post data and Headers usint it..
    I tried, but I couldn't make it work
    So, please anyone can make it..really need that..
    Last edited by WRYWERT; Jul 31st, 2007 at 09:29 AM.

  9. #49
    New Member
    Join Date
    Nov 2006
    Posts
    10

    Re: Winsock: HTTP File Upload

    Quote Originally Posted by visualAd
    It probably has something to do with the code page or character set used in Visual Basic. As I don't have a Chinese OS, I cannot test this. Your OS most probably uses Unicode (an encoding format not supported via HTTP).

    For text files, the majority of characters will be within the extended ASCII range (<255). I would imagine what is happening with binary files, is that as each character is represented by 2 bytes instead of 1, the high order byte is being truncated and hence lost.

    Have a look at this unicode FAQ posted by Merri.

    http://www.vbforums.com/showthread.php?t=365738

    In any case, I recommend that you convert all the strings to UTF-8 (the extended ASCII equivalent of Unicode) as this will ensure characters with codes above 256 are handled properly by the server.
    My recommendation is that you convert the data to UTF-8 encoding.


    I have a similar problem, but don't know at which place in vb coding i have to convert data to utf-8???

    or can i use the following line in BuildFileUploadRequest() function

    Content-Type: multipart-form-data;charset=utf-8, boundary=boundary

  10. #50
    Fanatic Member
    Join Date
    Oct 2007
    Posts
    544

    Re: Winsock: HTTP File Upload

    Can anyone show me the VB code for the program? Also is there a good winhttp code for the program?

    Finally, can we use webbrowser control to upload files onto web?

    I noticed that webbrowser control also allow us to post directly on the site.

    However we need to create the post requests first. Is there a fast way to decide that post requests?
    Last edited by teguh123; Oct 31st, 2007 at 01:18 AM.

  11. #51
    New Member
    Join Date
    Apr 2008
    Posts
    1

    Thumbs up Re: Winsock: HTTP File Upload

    Quote Originally Posted by hellilyntax
    thanks a lot visualAd,
    it sound quite hard for that coding...
    me either didnt plan to do so...hehe...

    im better choose another solution...
    im planning to update my sql server directly from my vb local client instead of upload the file then update at the server.

    which one is better in terms of reliability?
    Hi, If you want add support for http authentication you could add that line in the source:
    Code:
        ' construct the HTTP request in the form:
        '
        ' POST /path/to/reosurce HTTP/1.0
        ' Host: host
        ' Content-Type: multipart-form-data, boundary=boundary
        ' Content-Length: len(strbody)
        '
        ' HTTP request body
        strHttp = "POST " & DestUrl.URI & "?" & DestUrl.Query & " HTTP/1.0" & vbCrLf
        strHttp = strHttp & "Host: " & DestUrl.Host & vbCrLf
        ' HTTP Authentication LINE BELOW HERE
        strHttp = strHttp & "Authorization: Basic YWRtaW4xNDptdXNpd2ViMDMwNg==" & vbCrLf
        strHttp = strHttp & "Content-Type: multipart/form-data, boundary=" & strBoundary & vbCrLf
        strHttp = strHttp & "Content-Length: " & lngLength & vbCrLf & vbCrLf
        strHttp = strHttp & strBody
    
        BuildFileUploadRequest = strHttp

  12. #52
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Winsock: HTTP File Upload

    Thanks for the code visualAd. I was able to get most of it done myself before I saw this using a packet sniffer, but I was curious about the "boundaries". They can really be random?

    Edit:
    After reading more on it, boundaries are indeed random, and are nothing but delimiters that should be guaranteed to not appear in the files being uploaded (which would confuse the webserver).
    Last edited by DigiRev; May 26th, 2008 at 04:33 AM.

  13. #53

    Thread Starter
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Winsock: HTTP File Upload

    Yes,v as long as that sequence of characters appears nowhere in the file payloads.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  14. #54
    New Member
    Join Date
    Aug 2008
    Posts
    1

    Re: Winsock: HTTP File Upload

    hi, i need ur help. how to download http file using winsock? can u give me the visual basic 6 and php code? thx b4.

  15. #55

    Thread Starter
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Winsock: HTTP File Upload

    Quote Originally Posted by mauren
    hi, i need ur help. how to download http file using winsock? can u give me the visual basic 6 and php code? thx b4.
    I charge $50 per/hour for that service and a minimum fee of $300.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  16. #56
    New Member
    Join Date
    May 2010
    Posts
    2

    Re: Winsock: HTTP File Upload

    Any way this code can be converted into Visual Basic 2010?

  17. #57
    New Member
    Join Date
    Jun 2010
    Posts
    8

    Re: Winsock: HTTP File Upload

    Hello and hopefully youi're still monitoring this forum,

    I'm trying to get the demo program to upload files to my website but it's not working for some reason. I receive an HTTP Response of "HTTP/1.1 200 OK" but the test file (url.bas) doesn't show up in the HTTP Response window of the demo program and the file is not found on my website in the Uploaded_Files/Files directory.

    Here's what I'ver done (maybe you'll see what I've missed):

    1. Created an example folder on my website and placed post_dump.php and uploaded_files.php in this folder.

    2. Create uploaded_files folder and the files folder as a subfolder to the uploaded_files folder

    3. Set Permissions of the Files folder to 777

    4. Ran the demo program and tried to upload url.bas. Set the MIME Type to text/plain

    5. Here's what is returned in the HTTP Response window:

    HTTP/1.1 200 OK
    Date: Wed, 15 Sep 2010 21:33:49 GMT
    Server: Apache/2.2.16 (CentOS) mod_ssl/2.2.16 0.9.8l DAV/2 mod_fcgid/2.3.5 mod_auth_passthrough/2.1 FrontPage/5.0.2.2635
    X-Powered-By: PHP/5.2.13
    Vary: Accept-Encoding
    Content-Length: 0
    Connection: close
    Content-Type: text/htm

    Thanks and I look forward to a reply from you!

    Vic
    Last edited by vicspainhower; Sep 15th, 2010 at 05:13 PM.

  18. #58
    New Member
    Join Date
    Jun 2010
    Posts
    8

    Re: Winsock: HTTP File Upload

    ** Update ** - Well it never fails I ask for help and then I immediately find the answer. Very strange, I thought I'd add some comments in the PHP code to see what was going on and I only added a startup message in the post_dump.php file and presto message displayed and the file uploaded. Beats the heck out of me but it's now working fine. Now I have to integrate this into the application where it's needed.

  19. #59
    New Member
    Join Date
    May 2010
    Posts
    2

    Re: Winsock: HTTP File Upload

    vicspainhower: you mind giving me the code you used? I tried to use it on Vista x64 and x86 but I keep getting an error. It works great in XP.

  20. #60
    Lively Member
    Join Date
    Jun 2005
    Posts
    94

    Re: Winsock: HTTP File Upload

    There is no Progress bar added to this code. No way to check how many bytes transferred? I want to add Progress bar notification to the GUI. Any idea how can I achieve this?

  21. #61
    New Member
    Join Date
    Nov 2010
    Posts
    1

    Re: Winsock: HTTP File Upload

    Hi!
    I have download the file_upload to send a file via http and vb6 to a webside.

    It works wonderful but how can I change it to send more files.
    Hope you can help me there what I must change.

    kindly regards

  22. #62
    New Member
    Join Date
    Apr 2008
    Posts
    15

    Re: Winsock: HTTP File Upload

    To implement HTTPS you will need to create an encrypted SSL session. There are two ways to do this at www.coastrd.com.

  23. #63
    New Member
    Join Date
    Jun 2010
    Posts
    8

    Re: Winsock: HTTP File Upload

    Timetell - Hope this works for you - I'm using it on a Windows 7 64bit machine.

    Code:
    ' Calling Routine
    
      URL = "http://maps.google.com/?f=q&source=s_q&hl=en&geocode=&q=http://www.website.com/GoogleMaps/uploaded_files/files/"
        
      URL = URL & SiteName & ".kml"
      kmlFile = SiteName & ".kml"
        
      URL = URL & "&sll=" & dLatitude & "," & dLongitude & "+++++++++++++*-----&sspn=0.104398,0.179043&layer=t&ie=UTF8&ll=" & dLatitude & "," & dLongitude
      URL = URL & "&spn=0.001148,0.001399&t=h&z=20&lci=com.panoramio.all"
      Call UploadRoutine(App.Path & "\GoogleEarth\" & kmlFile)
      ShellExecute Me.hwnd, "open", URL, vbNullString, "", 0
    
      exit sub
    	
    
    ' this routine does all the work - it gathers the info required for the HTTP request
    ' and sends it via the winsock control
    Private Sub UploadRoutine(FileName As String)
        Dim strFile As String
        Dim strHttp As String
        Dim DestUrl As URL
        
        ' if a request is allredy being sent
        ' exit
        If blnConnected Then Exit Sub
        
        ' check that a file was selected
        If FileName = vbNullString Then
            MsgBox "No File Chosen", vbCritical, "ERROR"
            
            Exit Sub
        End If
    
        ' extract the URL using a helper function
        DestUrl = ExtractUrl("http://www.perfected.com/GoogleMaps/post_dump.php")
        
        If DestUrl.Host = vbNullString Then
            MsgBox "Invalid Host", vbCritical, "ERROR"
            
            Exit Sub
        End If
        
        ' clear the old response
        txtResponse.Text = ""
        
        ' read the file contents as a string
        ' N.B: in HTTP everything is a string, even binary files
        strFile = GetFileContents(FileName)
        
        ' build the HTTP request
        strHttp = BuildFileUploadRequest(strFile, DestUrl, "File", FileName, "text/plain")
        
        ' assign the protocol host and port
        Winsock1.Protocol = sckTCPProtocol
        Winsock1.RemoteHost = DestUrl.Host
        
        If DestUrl.Port <> 0 Then
            Winsock1.RemotePort = DestUrl.Port
        Else
            Winsock1.RemotePort = 80
        End If
                
        ' make the connection and send the HTTP request
        Winsock1.Connect
        
        While Not blnConnected
            DoEvents
        Wend
        
        txtRequest = strHttp
        Winsock1.SendData strHttp
        DoEvents
    End Sub
    
    
    ' this function builds a http request based on the following parameters:
    '
    ' data = the data from the file to be uploaded
    ' DestUrl = a URL to containing information on where to send the data
    ' UploadName = the field upload name usually pass by <input type="file" name="uploadname"
    ' Filename = the name of the file
    ' The MIME type of the file
    
    Private Function BuildFileUploadRequest(ByRef strData As String, _
                                            ByRef DestUrl As URL, _
                                            ByVal UploadName As String, _
                                            ByVal FileName As String, _
                                            ByVal MimeType As String) As String
        
        Dim strHttp As String ' holds the entire HTTP request
        Dim strBoundary As String 'the boundary between each entity
        Dim strBody As String ' holds the body of the HTTP request
        Dim lngLength As Long ' the length of the HTTP request
            
        ' create a boundary consisting of a random string
        strBoundary = RandomAlphaNumString(32)
        
        ' create the body of the http request in the form
        '
        ' --boundary
        ' Content-Disposition: form-data; name="UploadName"; filename="FileName"
        ' Content-Type: MimeType
        '
        ' file data here
        '--boundary--
        strBody = "--" & strBoundary & vbCrLf
        strBody = strBody & "Content-Disposition: form-data; name=""" & UploadName & """; filename=""" & _
                        FileName & """" & vbCrLf
        strBody = strBody & "Content-Type: " & MimeType & vbCrLf
        strBody = strBody & vbCrLf & strData
        strBody = strBody & vbCrLf & "--" & strBoundary & "--"
        
        ' find the length of the request body - this is required for the
        ' Content-Length header
        lngLength = Len(strBody)
        
        ' construct the HTTP request in the form:
        '
        ' POST /path/to/reosurce HTTP/1.0
        ' Host: host
        ' Content-Type: multipart-form-data, boundary=boundary
        ' Content-Length: len(strbody)
        '
        ' HTTP request body
        strHttp = "POST " & DestUrl.URI & "?" & DestUrl.Query & " HTTP/1.0" & vbCrLf
        strHttp = strHttp & "Host: " & DestUrl.Host & vbCrLf
        strHttp = strHttp & "Content-Type: multipart/form-data, boundary=" & strBoundary & vbCrLf
        strHttp = strHttp & "Content-Length: " & lngLength & vbCrLf & vbCrLf
        strHttp = strHttp & strBody
    
        BuildFileUploadRequest = strHttp
    End Function

  24. #64
    New Member
    Join Date
    Sep 2011
    Posts
    1

    Re: Winsock: HTTP File Upload

    i can Upload from here http://dev.mdimranhossain.com/uplod.php to my server with browser. But it doesn't work with this application with post method. when I submit with it the showing me 400 bad request. Please help me some one

  25. #65
    New Member
    Join Date
    Mar 2012
    Posts
    1

    Re: Winsock: HTTP File Upload

    Hi !

    This script is working great for me

    Is it maybe possible to add some post variables to that script ?

    if someone can help me with that, all is working 100% for me

  26. #66
    New Member
    Join Date
    Aug 2013
    Posts
    15

    Re: Winsock: HTTP File Upload

    Sorry for bumping an old thread.
    But I need a progress bar added to this.
    Can anyone help me please? I don't have any ideas about how it can be done.

Page 2 of 2 FirstFirst 12

Posting Permissions

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



Click Here to Expand Forum to Full Width