BLANK Image Uploaded to the webserver

Hi Experts,

I am using VB 6.0 an an XP machine. I am trying to upload images to an IIS 6.0 webserver using Inet control over HTTP . I use the PUT command for putting the image file (from client machine) on the server. The file is being put there successfully. But the problem is that the "jpg" image file which is put on the server is blank. There is no data in the image. Below is my code. Please help in figuring out what is wrong.

Private Sub Command1_Click()
   Inet1.AccessType = icUseDefault
   Inet1.URL = "http:// IP: PORT/login.cfm"
 
  Dim strSourceFile As String
  Dim strDestinationFile As String
   
  strSourceFile = "C:\Documents and Settings\pmud\Desktop\001.jpg"
 
   
  Inet1.Execute "http://IP:PORT/pmud/001.jpg", "PUT", strSourceFile
  MsgBox "File successfully created"
   
   Do While Inet1.StillExecuting
      DoEvents
   Loop

MsgBox "executed"

End Sub

Do I  need to use GetChunks to get the data from the oprn file and then put the file on the server and then open that file on the server and then write data to it? I tried using this approach but it was all messed up. If possible, can you post some code that will be helpful? I have been trying this since a 2 days but with no luck.

Thanks for any help.
pmudAsked:
Who is Participating?
 
DarthModCommented:
PAQed with points refunded (500)

DarthMod
Community Support Moderator
0
 
pmudAuthor Commented:
Hi,

I modified my code now so that it will read the binary data from the source file. But I am not sure how to out that data on the server. Below is my code:

Private Sub Command1_Click()
     
   Inet1.AccessType = icUseDefault
   Inet1.URL = "http://IP:PORT/login.cfm"
 
    Dim strSourceFile As String
    strSourceFile = "C:\Documents and Settings\pmud\Desktop\001.jpg"
     
    Dim fl As Long
    Dim binbyte() As Byte
    Dim readBinFile() As Byte
    Dim FileNo As Long
   
    FileNo = FreeFile
    Open "C:\Documents and Settings\pmud\Desktop\001.jpg" For Binary Access Read As #FileNo
      fl = FileLen("C:\Documents and Settings\pamud\Desktop\001.jpg")
      ReDim binbyte(fl)
       Get #FileNo, , binbyte
     Close #FileNo

    Inet1.Execute "http://IP: PORT/Test/003.jpg", "PUT", binbyte
      MsgBox " file created"
   
    Do While Inet1.StillExecuting
        DoEvents
    Loop
   
    MsgBox "executed"
End Sub

Do I need to open the file which is created on the server and then put data on that? If so, then how do I open the file which is on the server?

Thanks for any help


0
 
pmudAuthor Commented:
Hi,

I got the solution. Now the image is not blank . :)) I used the IP address of the server to open the file and write to it using the Put command. Below is my code:

 
Private Sub Command1_Click()
     
   Inet1.AccessType = icUseDefault
   Inet1.URL = "http://IP:PORT/login.cfm"
 
    Dim strSourceFile As String
    strSourceFile = "C:\Documents and Settings\pmud\Desktop\001.jpg"
     
    Dim fl As Long
    Dim binbyte() As Byte
    Dim readBinFile() As Byte
    Dim FileNo As Long
   
    FileNo = FreeFile
    Open "C:\Documents and Settings\pmud\Desktop\001.jpg" For Binary Access Read As #FileNo
      fl = FileLen("C:\Documents and Settings\pmud\Desktop\001.jpg")
      ReDim binbyte(fl)
       Get #FileNo, , binbyte
     Close #FileNo

 Dim FileNum As Long
     FileNum = FreeFile
       
    Open "\\IP \C$\Test\008.jpg" For Binary Access Write As #FileNum
        MsgBox "Server file opened"
        'Put data into the image
        Put #FileNum, , binbyte
    Close #FileNum
      MsgBox " file created"
   
    Do While Inet1.StillExecuting
        DoEvents
    Loop
   
    MsgBox "executed"
End Sub

Thanks

Thanks
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
junglerover77Commented:
Your solution is not a real solution to upload a file to a HTTP server. It just copies a file to a FILE server.

To upload a file to a HTTP server, you must make a server page which will accept a file upload (using ASP, PHP, JSP, whatever), and then use winsock to simulate a browser action of uploading a file.
0
 
junglerover77Commented:
Here is a sample code, but it's in C++. You can have a look.

http://support.microsoft.com/kb/q184352/
0
 
pmudAuthor Commented:
Hi junglerover,

Thanks for your response. I had a feeling that my code was not a good way to use HTTP with Inet. I looked at the code in C++. Its a helpful. But the problem is that I am not good with c or C ++ . I will try to convert this into VB 6.0 . But it would be great if you have any ideas on how to do it in vb.

Thanks for your help.
0
 
pmudAuthor Commented:
Hi,

I got the solution . Below is the code which worked for me. Thanks again for all your help.  :)

Private Sub Command1_Click()
Dim strPostData As String
Dim strHeader   As String
Dim strData     As String
     
    Open "C:\Documents and Settings\User\Desktop\001.jpeg" For Binary As #2            'open a heavy file for sending as POST DATA
    strData = Input(FileLen("C:\Documents and Settings\User\Desktop\001.jpeg"), #2)    'get the file contents in the variable
    Close #2                                        'close the file
     
    'prepare the post string
    strPostData = strData & vbCrLf
    MsgBox strPostData
    'prepare teh header string
    strHeader = "Content-Type: application/x-www-form-urlencoded" & vbCrLf
    'open the url
    Inet1.Execute "http://IP:Port/testData/ZZZZZZ.jpeg", "PUT", strPostData, strHeader
     MsgBox "Done"
     
End Sub

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.