Add PDF to MySQL BLOB field

Last post 01-14-2009 12:02 AM by aspnewbieperson. 8 replies.

Sort Posts:

  • Add PDF to MySQL BLOB field

    12-11-2008, 8:33 PM

    Hey,

    I have a pdf that is stored on the server and I want to be able to import it into a mysql database using asp.net 2.

    I have the database etc all ready to go with the field set up as a blob. The pdf file is only ~3kb.

    I've tried a couple of things, but I'm sort of stuck with the actual process of getting that file into the db - ie. i'm not sure if it needs to be opened first, then read into an inputstream, etc and what type the input parameter needs to be set to (eg. MIMEType, or String, etc).

    Can anybody help out with some code for the Parameters and method of getting that pdf into the db using SQL

    Please click "Mark As Answer" if indeed this is the case.
  • Re: Add PDF to MySQL BLOB field

    12-14-2008, 4:37 PM
  • Re: Add PDF to MySQL BLOB field

    12-14-2008, 4:51 PM

    Thanks for the info, but the articles you linked to are not what I asked for :)

    I am after a method of importing a file that already exists on the server into the database. It is not for uploading a file from a local computer on the server and reading the HttpPostedFile.

    Thanks anyway.

    Please click "Mark As Answer" if indeed this is the case.
  • Re: Add PDF to MySQL BLOB field

    12-15-2008, 8:29 AM
    Answer
    • Member
      385 point Member
    • trdudei
    • Member since 05-10-2007, 3:58 PM
    • WI
    • Posts 71

    I got that - the part of the links I was referring to was the file-to-database portion...  Not the upload.  2 of the articles talked about saving to SQL and the last about Oracle...  Here's another shot...

    from http://support.microsoft.com/kb/326502...

     Dim con As New SqlConnection("Server=yileiw2;uid=sqlauth;pwd=sqlauth;database=pubs")
            Dim da As New SqlDataAdapter("Select * From pub_info", con)
            Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)
            Dim ds As New DataSet()

            da.MissingSchemaAction = MissingSchemaAction.AddWithKey
            con.Open()
            da.Fill(ds, "Pub_info")

            Dim fs As New FileStream _
             ("C:\SomePath\MyPhoto.jpg", FileMode.OpenOrCreate, _
              FileAccess.Read)
            Dim MyData(fs.Length) As Byte
            fs.Read(MyData, 0, fs.Length)
            fs.Close()
            ds.Tables("Pub_info").Rows(0)("logo") = MyData
            da.Update(ds, "Pub_info")

            fs = Nothing
            MyCB = Nothing
            ds = Nothing
            da = Nothing

            con.Close()
            con = Nothing
            Response.Write("File saved to database")

    I realize you're not working with SQL but I would think the coding is similar...

     

  • Re: Add PDF to MySQL BLOB field

    12-15-2008, 8:32 AM
    • Member
      385 point Member
    • trdudei
    • Member since 05-10-2007, 3:58 PM
    • WI
    • Posts 71

    (that's mysql, not Oracle...  Oops...)

  • Re: Add PDF to MySQL BLOB field

    12-15-2008, 9:27 AM

    No worries, I'll give that a shot tomorrow and let you know, thanks heaps. It looks like it should work with a little tweaking for MySQL.

    Big Smile 

    Please click "Mark As Answer" if indeed this is the case.
  • Re: Add PDF to MySQL BLOB field

    12-16-2008, 2:54 AM

    With a little tweaking, it's now working pretty much using the code provided above.

    Thank you!! Big Smile

    Please click "Mark As Answer" if indeed this is the case.
  • Re: Add PDF to MySQL BLOB field

    01-07-2009, 5:36 AM
    • Member
      2 point Member
    • alanaxford
    • Member since 01-07-2009, 10:33 AM
    • Posts 1

    may try Navicat, http://www.navicat.com. I've been using it for 3 yrs and it's the best mysql gui I ever used.

  • Re: Add PDF to MySQL BLOB field

    01-14-2009, 12:02 AM

    alanaxford:

    may try Navicat, http://www.navicat.com. I've been using it for 3 yrs and it's the best mysql gui I ever used.

     

    Please don't post spam links as you obviously didn't even read the posts above.

    Please click "Mark As Answer" if indeed this is the case.
Page 1 of 1 (9 items)