• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 421
  • Last Modified:

UPLOAD Images to IIS WebServer


I need to upload images to an IIS webserver using HTTP POst. I read that Winsock and INet controls can do that. But I am at a total loss. I have been trying for the past 2 weeks and I am not getting it.

Can anyone please post the code they have for doing this. I tried the following code, but it doesnt upload the file, it just copies it. The server might necessarily allow access to its drives, so my copying code wont work... Please some help. Below is the code I used.  Please if someone has a method with Winsock or with something else which uses  HTTP POst... It will be great.

 Inet1.Protocol = icHTTP
     Inet1.AccessType = icUseDefault
     Inet1.URL = "http://IP:PORT/clerical.cfm"
      Dim strSourceFile As String
      strSourceFile = SubDir(m) & "\" & FileToUpload
      Dim fl As Long
      Dim binbyte() As Byte
      Dim readBinFile() As Byte
      Dim FileNo As Long

      FileNo = FreeFile()
      Debug.Print FileNo
      Open strSourceFile For Binary Access Read As #FileNo
      Debug.Print strSourceFile
      fl = FileLen(strSourceFile)
      ReDim binbyte(fl)
       Get #FileNo, , binbyte
      Close #FileNo
    Dim FileNum As Long
    Dim strServerDirPath, strSubServerDirPath As String
    strServerDirPath = "\\IP\C$\Data\patients\" & strServerFolder
    strSubServerDirPath = strServerDirPath & "\" & strSubServerFolder
         FileNum = FreeFile
       Open strSubServerDirPath & "\" & FileToUpload For Binary Access Write As #FileNum
        'Put data into the image
          Put #FileNum, , binbyte
          Close #FileNum
         MsgBox "Image " & FileToUpload & " Uploaded."
       Do While Inet1.StillExecuting

I also looked at http://www.vbforums.com/showthread.php?t=337424 , but it doesnt upload any images to the server.

Any kind of help will be extremely appreciated.

  • 5
  • 4
1 Solution
Try looking at this link

Sorry, I normally don't post a link and run.  You don't need to use winsock and Inet to upload files.  Those controls would be best used in a compiled application or an ActiveX control.  The link I posted will teach you how to use pure ASP to upload files.  I've used it before and I currently use it at work but it's one of those "program it and forget it" type programs.

As far as Server permissions go, you're still going to need permissions on the server.  That's going to depend on your server administrator.  Simply put, not all administrators allow "Posting" to the file system.  However, the code in the link will show you how to post binary objects (i.e. pictures, word documents, etc...) to a database instead.  As far as getting the objects out of the database, that's a whole new world of headaches that you'll have to search for answers in a new thread for.


pmudAuthor Commented:
Hi dds110,

I am using this code within an ActiveX control only.

Thanks for any help.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

pmudAuthor Commented:
Hi dds110,

I am using Acti9veX so Winsock ot Inet should work. I need to use VB 6.0 for doing this. Please let me know if you have any more ideas.

I really can't be much of any help to you at the moment because they won't let me have VB at work.  However, since you're posting to a web server and not an FTP or File server, I'd recommend using the solution at the link I originally posted.  The reason:

Different Servers have Different Permissions.  In other words, INet and Winsock are simply wrappers for Network File operations (ok, I know they do more than that but I'm trying to keep it simple).  You're trying to upload images to a web server which requires different permissions based on the server software.  I'm sure you can do it with Winsock and INet, but you've already spent two weeks with no relief in sight.  How much more time are you willing to spend on it.  I'll look for some more links to see if I can help you gain any more insight.
pmudAuthor Commented:
Hi dds110,

I started reading the article you mentioned and in Operstaing systems supported link on the main page, it doesnt list XP . Most clients use Windows XP . I dont think this will work if it doesnt support XP.

Also, do I have to downlaod this component and distribute it along with my ActiveX control CAB file?

Thanks for your help.
Watch out, here comes another link.............


That link is for the code we use where I work.  Take a look at it and let me know what you think.  It supports XP, I promise.
pmudAuthor Commented:
Hi dds110,

I got the solution . Below is the code which worked for me.
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

Your code is much simpler and smaller than what's in the link I posted.  I think I may try it out.  I'm sorry I couldn't have been more usefull to you.  Good luck with your programming.
PAQed with points refunded (500)

Community Support Moderator

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now