Blogs / SAP / SAP BW/HANA / SAP HANA / Storing Images (BLOB) in SAP HANA using Python

Storing Images (BLOB) in SAP HANA using Python

May 21, 2019


In this blog, we will demonstrate how to convert an image into a BLOB object using Python and store it in the HANA database.

BLOB is the acronym for Binary Large Object File (BLOB) which can store images/other files in the binary format up to a maximum of 2 GB. The functionality demonstrated here can also be extended to other BLOB objects such as audio, video and pdf files.


  1. Install Python along with the required SAP libraries (Refer to GitHub repository for more details
  2. Establish a connection between Python and HANA DB
  3. Convert object using Python
  4. Insert the BLOB object into a HANA table
  5. Consume the HANA table/view in SAP Analytics Cloud

In the example below, the SAP Analytics Cloud application has been developed to analyze the details of a customer.

Customer details, logos/images have been taken from the HANA table where they are stored as BLOBs.

Storing Images (BLOB) in SAP HANA using Python

Implementation details

In order to consume BLOBs in SAP Analytics Cloud (SAC), we require it to be of the format ST_MEMORY_LOB. Hence, the table also needs to be defined in the following format;


After creating the table, the connection from Python to HANA DB needs to be established using its corresponding host/port number and credentials. This connection can then be verified by triggering a dummy SQL query.

Now, the required image file can be converted to BLOB in Python by just reading it.

In this example, ‘Hana1.png’ is converted using a read statement. ‘binaryData’ contains the image in the encoded Binary Format.

Storing Images (BLOB) in SAP HANA using Python

Create a connection to HANA using ‘pyhdb.connect()’ along with the required connection details. Then we can define a cursor in HANA and leverage it for executing the necessary commands.

Cursor.execute(‘INSERT INTO <SCHEMA_NAME>.<TABLE_NAME> Values (‘Hana1.png’,binaryData)’)

‘Hana1.png’ refers to the filename and acts as the primary key while ‘binaryData’ is the corresponding BLOB. Once the execution is successful, we can commit this cursor to insert a row in our HANA table.

Now, we have successfully inserted and stored an image into the HANA table. This table can be joined with other tables/views and consumed in SAP Analytics Cloud using HANA live connectivity.

Read our other blogs on SAP HANA here.

Learn more about Visual BI Solutions  SAP HANA services offerings here. 

Corporate HQ:
5920 Windhaven Pkwy, Plano, TX 75093

+1 888-227-2794

+1 972-232-2233

+1 888-227-7192

Copyright © Visual BI Solutions Inc.

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

Share This!

Share this with your friends and colleagues!