# Oracle BLOB column with jdbc input to base64

**URL:** <https://discuss.elastic.co/t/oracle-blob-column-with-jdbc-input-to-base64/276830>\
**Category:** Logstash\
**Created:** [June 23, 2021, 5:34pm UTC](https://discuss.elastic.co/t/oracle-blob-column-with-jdbc-input-to-base64/276830 "2021-06-23T17:34:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexanders](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@alexanders](https://discuss.elastic.co/u/alexanders)\
**Post date:** [June 23, 2021, 5:34pm UTC](https://discuss.elastic.co/t/oracle-blob-column-with-jdbc-input-to-base64/276830/1 "2021-06-23T17:34:42Z")

</div>

When fetching an Oracle BLOB column with logstash's jdbc input, I try to convert it to base64 using the following filter:

```auto
ruby { 
    code => 'event.set("b64", Base64.strict_encode64(event.get("blob_column")))' 
  }

```

which yields valid base64. However, when decoding the b64 string, the content is different from the BLOB content. It seems as if, at some place, an encoding conversion was attempted, because bytes that can be represented as printable ASCII remain unchanged, while others are replaced by the replacement character U+FFFD � or a "zero literal" \u0000.  
Is there a way to keep the column value without any further encoding as the original byte sequence, in order to create a base64 string?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [June 23, 2021, 6:24pm UTC](https://discuss.elastic.co/t/oracle-blob-column-with-jdbc-input-to-base64/276830/2 "2021-06-23T18:24:07Z")

</div>

Are you setting the charset or columns\_charset options on the jdbc input?

---

<div class="post-metadata">

**Author:** ![alexanders](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@alexanders](https://discuss.elastic.co/u/alexanders)\
**Post date:** [June 24, 2021, 7:23am UTC](https://discuss.elastic.co/t/oracle-blob-column-with-jdbc-input-to-base64/276830/3 "2021-06-24T07:23:40Z")

</div>

I tried

```auto
columns_charset => {
      "blob_column" => "BINARY"
}

```

already, but still same behavior.

---

<div class="post-metadata">

**Author:** ![alexanders](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@alexanders](https://discuss.elastic.co/u/alexanders)\
**Post date:** [July 5, 2021, 7:54am UTC](https://discuss.elastic.co/t/oracle-blob-column-with-jdbc-input-to-base64/276830/4 "2021-07-05T07:54:03Z")

</div>

I found a solution that suits my needs. This refers to logstash in docker, image `logstash:7.13.1`.

I modified the following ruby file  
`/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-integration-jdbc-5.0.7/lib/logstash/plugin_mixins/jdbc/jdbc.rb`  
to create a base64 string from any Sequel::SQL::Blob type.

```auto
***************
 ***256,271****
--- 256,273 ----
      private
      def decorate_value(value)
        case value
        when Time
          # transform it to LogStash::Timestamp as required by LS
          LogStash::Timestamp.new(value)
        when Date, DateTime
          LogStash::Timestamp.new(value.to_time)
+ when Sequel::SQL::Blob
+ Base64.strict_encode64(value.to_s)
        else
          value
        end
      end
    end
  end end end

```

The filter in the pipeline's configuration is not needed anymore.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 2, 2021, 7:54am UTC](https://discuss.elastic.co/t/oracle-blob-column-with-jdbc-input-to-base64/276830/5 "2021-08-02T07:54:53Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
