How to write an image to db

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default How to write an image to db

    Hello,
    how do i write an image from a file source to a database on sql-server via
    asp ? e.g:
    I try to store file c:\temp\test.jpg in the field "picture" in a recordset.
    The field "picture" is datatype image. How to do this ?




    Ralf Pelzl Guest

  2. Similar Questions and Discussions

    1. how to write AS class to have image in preloader
      I want to have a customised preloader, with a progressbar showing the percentage loaded and a predefined logo( .gif / .jpeg )in the initialization...
    2. write to database without giving write permission to IIS
      Hi there, I have some ASP code that writes to access database. For security reason I do not want IUSER to give write permission to database...
    3. JPG stored as long binary in database: how to write output as image in asp?
      Hello, For a while I am working with ThumbsPlus ( http://www.cerious.com/ ) as manager for pics. The benefit of the program is that it stores...
    4. How To Browse for an image file and save it to image server folder
      I trying to browse for an image file and save it to the server image folder. in other words , upload the picture. I tried html and aspx.net...
    5. Can I take a small (320x240), blurry image, and make it a clear, large image?
      Just wondering if there is an easy way to do this? I'm sure it won't be perfect cause photoshop can only work with what's there, but maybe it can...
  3. #2

    Default Re: How to write an image to db

    Here's something I wrote to do just that, all you need to do is fill in some
    gaps:

    <%
    Function GuestConnString()
    GuestConnString = "provider=sqloledb;data
    provider=sqloledb;server=xxxx;data source=xxxx;User
    ID=xxxx;password=xxx;Initial Catalog=xxxx;"
    End Function

    Function getHexStream(docPath)
    Dim loStream
    Set loStream = Server.CreateObject("ADODB.Stream")
    loStream.Open
    loStream.Type = 1 'adTypeBinary
    loStream.loadFromFile(docPath)

    ' Create an XML DOM document
    Set loXMLDoc = Server.CreateObject("MSXML2.DomDocument")
    loXMLDoc.async = False

    ' Create the node to hold file data
    Set loFile = loXMLDoc.CreateNode("element", "filedata", "")
    loFile.dataType = "bin.hex"
    loFile.nodeTypedValue = loStream.Read

    ' Get the HEX representation of the file
    getHexStream = "0x" & loFile.Text

    Set loStream = Nothing
    Set loFile = Nothing
    Set loXMLDoc = Nothing
    End Function

    Function InsertDocument(docPath)
    Dim loConn, lsSQL, lsFileExt, lsFileName
    Set loConn = Server.CreateObject("adodb.connection")
    loConn.Open GuestConnString

    lsFileName = Split(StrReverse(docPath), "\")(0)
    lsFileExt = StrReverse(Split(lsFileName, ".")(0))

    lsSQL = "sp_insertDocument '" & lsFileExt & "', " & getHexStream(docPath)

    On Error Resume Next
    loConn.Execute(lsSQL)
    loConn.Close
    Set loConn = Nothing

    InsertDocument = Err.Number
    End Function

    Dim lsFilePath
    lsFilePath = "c:\myfolder\mypic.jpg"

    If Not IsEmpty(lsFilePath) Then
    If InsertDocument(lsFilePath) = 0 Then
    Response.Write("File processed succesfully!")
    Else
    Response.Write("Failure during file procesing.")
    End If
    End If

    %>

    --
    Manohar Kamath
    Editor, .netBooks
    [url]www.dotnetbooks.com[/url]


    "Ralf Pelzl" <ralf.pelzl@inf.hs-anhalt.de> wrote in message
    news:OPINs%23mVDHA.2340@TK2MSFTNGP10.phx.gbl...
    > Hello,
    > how do i write an image from a file source to a database on sql-server via
    > asp ? e.g:
    > I try to store file c:\temp\test.jpg in the field "picture" in a
    recordset.
    > The field "picture" is datatype image. How to do this ?
    >
    >
    >
    >

    Manohar Kamath [MVP] Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139