Image Processing in SAP HANA

In this article we will learn:
  • How image is saved in HANA database in BLOB format
  • How to upload image in SAP HANA
  • How to download image from HANA and show in HTML
What is a BLOB?

BLOB (Binary Large Object) is a field type for storing Binary Data.
BLOB could store a large chunk of data, document types and even media files like audio or video files. In HANA the BLOB size can be up to 2 GB.

In HANA database, we can use BLOB data type to store image.

Create Image Table:

Let’s first create a table in HANA to store images.
Copy and paste below script to create table.
--REPLACE <SCHEMA_NAME> WITH YOUR SCHEMA NAME
CREATE COLUMN TABLE "<SCHEMA_NAME>"."IMAGE_STORE"(
    IMAGE_NAME NVARCHAR(20) PRIMARY KEY,
    IMAGE_CONTENT BLOB
);

Download some sample images:

Download some sample images and save in a folder.
For this example I downloaded some images of SAP HANA and saved in “C:\ImageToBeUploaded”


Upload images into HANA database:

There are several ways of uploading images into HANA database. For example: Java, Python etc.
Here we will use Java program to upload image.
Note: You can either use a different eclipse tool for java or use the same HANA Studio to create a Java project. If you are using HANA Studio, then make sure you have selected “SAP HANA Development” perspective.

1. Download the JAVA Project ImageUploader.zip and save it to your local computer.
2. Open JAVA Eclipse (or HANA Studio) and create a Java project called "ImageUploader".




3. Go to File --> Import --> General and select "Archive File".
4. Click on browse and select the " ImageUploader.zip " file you downloaded in step 1. Click on finish.


5. Open ImageUploader.java file and change the HANA system details.


6. Run the Java program. You should see similar message in console.


We have successfully uploaded the image files into HANA database.

Have the images really uploaded to HANA?

You might be wondering that have the files really uploaded to HANA. Let us check that.
Open HANA studio and open SQL console. Check the output of IMAGE_STORE table.

SELECT * FROM "<SCHEMA_NAME>"."IMAGE_STORE";


The output shows that image files are uploaded in BLOB format.

Download image from SAP HANA:

We need to create a HANA XS project to download the image from HANA.
1. Create a HANA XS project.


2. Download the zip file and extract it somewhere in your local system.
3. Copy all the content inside “ImageProcessing” folder.


4. Go to HANA Studio and paste everything inside


5. Open GetImage.xsjs file and change the YOUR_SCHEMA_NAME in first line to your schema name. Make sure it is the same schema where you created the “IMAGE_STORE” table.
Right click on the project and select Team --> Activate.

Done!!
6. Now let us test this.
Open ImageBrowser.html file under “ui” folder. Right click and select Run As --> HTML
Search for the image that you uploaded. If the image is found it will display the image.


You can search with the name of the images you uploaded.

If you have any question or doubt, please leave a comment or contact us.

2 comments:

  1. Couldn't download ImageUploader.zip, that link is not reachable

    ReplyDelete
  2. Hiiiii....Thank you so much for sharing Great information...Nice post...Keep move on...
    Best SAP HANA Training Institutes in Hyderabad

    ReplyDelete