Need help to download compressed PDF files Stored In an Oracle BLOB RRS feed

  • Question

  • User-1486682524 posted

    In a VB.net application that I am working on, we need to allow visitors to download PDF files that are compressed and stored in an Oracle database as a BLOB.  I am trying to find a way to get the data from the database, uncompress it and then send it to Response.Write.  Any help would be greatly appreciated.

    Tuesday, May 3, 2011 8:49 AM

All replies

  • User269602965 posted

    If the compression was done at the Oracle database table level, it will decompress on SELECT automatically.

    If the compression was done to the PDF file before storage, you will need to find out which of the many compression methods was used, and will need a code library to do the decompression specific to the method of compression (zip, lzh, arc, etc.)

    Extracting a BLOB is relatively easy with SYSTEM.IO, memory streams, and MIME type as key words to study.

    The application is what actually reads the memory stream as you apply the MIME TYPE in code and convert it to a format useable by the client add-on or application, in this case Acrobat Reader




    Tuesday, May 3, 2011 6:50 PM
  • User-1486682524 posted

    Hello Lannie - thanks for your help with my question.  The compression must not have been done at the Oracle level because it does not decompress when I select it.

    I have been experimenting with the BLOB data and I have found that it is zipped.  I have been able to put together some code that uses ICSharp to uncompress the data and save it as a file.  My problem is that instead of saving the data as a file, I would like to send it directly to Response.Write, so that visitors to the site can download it directly.  Here is the code that I have been able to use to uncompress and save as a file, I would appreciate any help with sending to Response.Write:


      Public Function ExtractArchive() As String
                Dim theExtractDir As String = "TestFiles"
                ' ICSharpCode Zip
                Dim Redo As Integer = 1
                Dim MyZipInputStream As ZipInputStream = Nothing
                Dim MyFileStream As FileStream = Nothing
                Dim strTheFileName As String = Nothing
                ' Oracle
                Dim con As OracleConnection = New OracleConnection(ConfigurationManager.ConnectionStrings("Tempo_Prod_ConnectionStringNoUnicode").ConnectionString)
                Dim cmd As OracleCommand = New OracleCommand()
                ' Get the data from Oracle
                cmd.Connection = con
                cmd.CommandText = strSQL
                Dim dr As OracleDataReader = cmd.ExecuteReader()

                ' Send the Oracle data to ICSharpCode Zip
                MyZipInputStream = New ZipInputStream(dr.GetOracleBlob(0))

                strTheFileName = dr.GetOracleString(1)

                Dim MyZipEntry As ZipEntry = MyZipInputStream.GetNextEntry
                While Not MyZipEntry Is Nothing
                    If (MyZipEntry.IsDirectory) Then
                        Directory.CreateDirectory(theExtractDir & "\" & MyZipEntry.Name)
                        If Not Directory.Exists(theExtractDir & "\" & _
                        Path.GetDirectoryName(MyZipEntry.Name)) Then
                            Directory.CreateDirectory(theExtractDir & "\" & _
                        End If

                        MyFileStream = New FileStream(theExtractDir & "\" & strTheFileName, FileMode.OpenOrCreate, FileAccess.Write)

                        Dim count As Integer
                        Dim buffer(4096) As Byte
                        count = MyZipInputStream.Read(buffer, 0, 4096)
                        While count > 0
                            MyFileStream.Write(buffer, 0, count)
                            count = MyZipInputStream.Read(buffer, 0, 4096)
                        End While
                    End If
                        MyZipEntry = MyZipInputStream.GetNextEntry
                    Catch ex As Exception
                        MyZipEntry = Nothing
                    End Try
                End While

               Return theExtractDir & "\" & strTheFileName


                If Not (MyZipInputStream Is Nothing) Then MyZipInputStream.Close()
                If Not (MyFileStream Is Nothing) Then MyFileStream.Close()
            Catch ex As Exception
                Return "Erros Occured"
            End Try

        End Function



    Wednesday, May 4, 2011 10:21 AM
  • User269602965 posted

    I have had trouble opening PDFs with Response Write at least using AJAX.

    So I save the stream as a file in a /PDF_DIR on the website with dynamically created name and open it from there.

    Likely the worst way to do it, but for intranet applications, it solved my endless headaches with Reponse Write and PDFs.

    Wednesday, May 4, 2011 5:19 PM