UPLOAD Images to IIS WebServer

Posted on 2006-05-31
Last Modified: 2013-11-13

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 , but it doesnt upload any images to the server.

Any kind of help will be extremely appreciated.

Question by:pmud
    LVL 8

    Expert Comment

    Try looking at this link
    LVL 8

    Expert Comment

    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.



    Author Comment

    Hi dds110,

    I am using this code within an ActiveX control only.

    Thanks for any help.

    Author Comment

    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.

    LVL 8

    Expert Comment

    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.

    Author Comment

    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.
    LVL 8

    Expert Comment

    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.

    Author Comment

    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

    LVL 8

    Expert Comment

    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.
    LVL 1

    Accepted Solution

    PAQed with points refunded (500)

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Suggested Solutions

    Title # Comments Views Activity
    sameEnds challenge 25 55
    countClumps  challenge 10 68
    wordlen challenge 3 27
    message box in access 4 19
    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    This video teaches viewers about errors in exception handling.
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now