Results 1 to 8 of 8

Thread: Need new solution !

  1. #1

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606

    Need new solution !

    Hello,

    For my project, i need to upload some files to an ASP file on a server(i don't have control on the ASP on the server, it's another guys that does that, because i don't have my security clearance).

    At first i wanted to use the web browser control, load a form in it, set it's file value to my document(c:\temp\somefile.xml), but i just found out that i can input the value of a file input with code !

    So now what to do, i basically need to pass my document to an ASP file on a server, how can i do this, can i do it with the INET control ? If yes, how would I go about it!

    Tx

  2. #2

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    ok, i think i need to use the inet control!

    but how to upload a file in binary

    Inet.Execute([URL],[operation],[inputData],[inputHdrs])

    so how would i use that

    Inet.Execute "http://www.myserver.com/myfile.asp",,myFileContent,"Content-Type: multipart/form-data; and what else"

    what do i need to put in the header and my file content, should it be my file in s string, in a byte array ??

    tx again !

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    You can use the WebBrowser control, you just need to be a little creative with your solution.

    For example, you can send TABS to the WebBrowser window until you're in the File textbox,
    then paste the filename/location you want to upload and hit the submit button.

    Depending on how you implement this you can have a suprising amount of control over the process.

    Here's an example using the vbforums "Search" field:
    VB Code:
    1. Option Explicit
    2.  
    3. Private mbComplete As Boolean
    4.  
    5. Private Sub cmdWebFile_Click()
    6.  
    7.   If Not fnNavWeb("www.vbforums.com") Then Exit Sub
    8.  
    9.   ' Set Focus to the "query" INPUT element
    10.   Do
    11.     If WebBrowser1.Document.ActiveElement.NodeName = "INPUT" Then
    12.       If StrComp(WebBrowser1.Document.ActiveElement.Name, "query", vbTextCompare) = 0 Then Exit Do
    13.     End If
    14.     ' Set Focus to the WebBrowser Control and Tab
    15.     WebBrowser1.SetFocus
    16.     SendKeys "{TAB}", True
    17.   Loop
    18.    
    19.   ' Set Focus to the WebBrwoser control
    20.   ' Copy the text to the clipboard, then
    21.   ' Paste it into the field.
    22.   WebBrowser1.SetFocus
    23.  
    24.   Clipboard.Clear
    25.   Clipboard.SetText txtFile.Text
    26.  
    27.   SendKeys "^v", True
    28.  
    29.   ' Now Tab to the Submit button and Press it
    30.   SendKeys "{TAB}", True
    31.   SendKeys "{ENTER}", True
    32. End Sub
    33.  
    34. Private Function fnNavWeb(ByVal URL As String) As Boolean
    35.   Dim tTimer As Single
    36.  
    37.   tTimer = Timer
    38.   mbComplete = False
    39.   WebBrowser1.Navigate2 URL
    40.  
    41.   Do While Not mbComplete And ((Timer - tTimer) < 30)
    42.     DoEvents
    43.   Loop
    44.   fnNavWeb = mbComplete
    45. End Function
    46.  
    47. Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    48.   If (pDisp Is WebBrowser1.Object) Then
    49.     mbComplete = True
    50.   End If
    51. End Sub
    This isn't a File field, however the same principle applies.

  4. #4

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    tx

    But, i tried to upload a file content to an ASP and write that content to the browser, and it did'nt work, that ASP files works when i use the file input, i think it's because when i sue the input file field, it send the file in a byte array, but if i copy and paste the file content in a text field, it's not a byte array, or so i understand it!

    And clearing the Clipboard, it's a risky thing to do, what if the user just copoy something important, i dunno if it's good to clear it!

    here's the code i'm using on my ASP file, it's modified for my testing!

    VB Code:
    1. <%
    2. Response.Expires = 0
    3. Response.Buffer = true
    4.  
    5. Private Function stringToByte(toConv)
    6.     Dim tempChar
    7.     For i = 1 to Len(toConv)
    8.         tempChar = Mid(toConv, i, 1)
    9.         stringToByte = stringToByte & chrB(AscB(tempChar))
    10.     Next
    11. End Function
    12.  
    13.  
    14. Dim sPos,ePos,x
    15.            
    16. Dim separator
    17. toConv=request.BinaryRead(Request.TotalBytes)          
    18. separator = MidB(toConv, 1, InstrB(1, toConv, ChrB(13)) - 1)
    19.  
    20. sPos=169
    21. ePos=InStrB(sPos,toConv,separator)     
    22. toConv=MidB(toConv,sPos,ePos-sPos)
    23.        
    24. Response.ContentType="image/jpeg"
    25. Response.BinaryWrite toConv
    26.  
    27. %>

    the inet control interest me, looks more solid, do you have any info and the inputheaders !!

  5. #5
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    You wouldn't paste the content of the file in the field, you would paste the location and filename in the field.

    The ASP page will then upload the specified file when it's submitted.

    I've used this solution myself and it works fine.

    You don't necessarily have to use the Clipboard, you could send the filename directly using the SendKeys command.

  6. #6

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    damm, i swear i had tried this, i figured that i could do the same thing if i just put the path in a text input, because the file input is mostly to make more user friendly, with the browse button!

    well it will work now, here's what i was using the input my value in my form

    VB Code:
    1. With web.Document
    2.         If testModeIsOn Then
    3.             .Forms("frmUpload").Action = testModeURL
    4.         Else
    5.             .Forms("frmUpload").Action = strFileToSend(3, intSentFileCpt)
    6.         End If
    7.         .Forms("frmUpload").manddi_doc.Value = strFileToSend(0, intSentFileCpt) 'this is the file to upload
    8.         .Forms("frmUpload").submit
    9.     End With

    i try it in my code and let you know the result, i just tried in html and it work

    tx a lot man

  7. #7

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    well, it's not working

    i thought it was, but when i opened the file, the path was in it, instead of the file content

    how do you do it!

    here what it's in my header

    Code:
    -----------------------------7d34a1153104aa
    Content-Disposition: form-data; name="manddi_doc"
    
    C:\TEMP\USCRP2032003193436_1.jpg
    -----------------------------7d34a1153104aa--
    there's no binary content

    am i missing something ?

    [edit]oh, and i forgot to mention that the file to upload is not on the same computer that the server is on![/edit]
    Last edited by sebs; Mar 23rd, 2003 at 03:22 PM.

  8. #8

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    now i'm in business

    i did the header thing with the webbrowser, works great, don't need a form at all

    here's how i built my header for the interested

    VB Code:
    1. Const Boundary As String = "---------------------------0123456789012"
    2. Dim bFormData() As Byte
    3. Dim strHeader As String
    4.  
    5.     strHeader = "--" & Boundary & vbCrLf
    6.     strHeader = strHeader & "Content-Disposition: form-data; name=""manddi_doc""; filename=""" & strFileToSend(0, intSentFileCpt) & """" & vbCrLf
    7.     strHeader = strHeader & "Content-Type: application/upload" & vbCrLf & vbCrLf
    8.     strHeader = strHeader & sFormData
    9.     strHeader = strHeader & vbCrLf & "--" + Boundary + "--" + vbCrLf
    10.  
    11.  
    12.   ReDim bFormData(Len(FormData) - 1)
    13.   bFormData = StrConv(strHeader, vbFromUnicode)
    14.  
    15.   web.Navigate myURL, , , bFormData, "Content-Type: multipart/form-data; boundary=" + Boundary + vbCrLf
    16.  
    17. Function GetFile(FileName As String) As String
    18.   Dim FileContents() As Byte, FileNumber As Integer
    19.   ReDim FileContents(FileLen(FileName) - 1)
    20.   FileNumber = FreeFile
    21.   Open FileName For Binary As FileNumber
    22.     Get FileNumber, , FileContents
    23.   Close FileNumber
    24.   GetFile = StrConv(FileContents, vbUnicode)
    25. End Function

    woks great !

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