Quantcast
Channel: Jim's PeopleSoft Journal
Viewing all articles
Browse latest Browse all 201

Accessing Database Photos from Query Access Service

$
0
0

I have been working with the PeopleTools 8.54 REST Query Access Services. I would absolutely LOVE them if they returned JSON instead of XML. With a little help from x2js I am able to work around this "shortcoming." One specific challenge I faced was accessing image data. For example, with PeopleSoft query I can see who has photos in PS_EMPL_PHOTO, but I can't see the actual uploaded photo. With a little help from Oracle and a query expression, however, I can convert the photo blob into base64:

SELECTUTL_RAW.CAST_TO_VARCHAR2(UTL_ENCODE.BASE64_ENCODE(EMPLOYEE_PHOTO))
FROM PS_EMPL_PHOTO
WHERE EMPLID ='KU0003'

The only problem with this approach is that Oracle database has a maximum size limit on data that can be encoded and most of the photos I have seen exceed that maximum. The way I chose to work around this limitation is to substring the blob and encode it in fragments. I create a separate column for each fragment, and then concatenate them together in the REST client. Here is some sample SQL from a PeopleSoft query. Each of the CASE statements is a query expression.

SELECT
CASE
WHENDBMS_LOB.GETLENGTH(EMPLOYEE_PHOTO)>1455THENUTL_RAW.CAST_TO_VARCHAR2(UTL_ENCODE.BASE64_ENCODE(DBMS_LOB.SUBSTR(EMPLOYEE_PHOTO, 1455, 1)))
WHENDBMS_LOB.GETLENGTH(EMPLOYEE_PHOTO)<=1455THENUTL_RAW.CAST_TO_VARCHAR2(UTL_ENCODE.BASE64_ENCODE(EMPLOYEE_PHOTO))
ENDAS C1,
CASE
WHENDBMS_LOB.GETLENGTH(EMPLOYEE_PHOTO)>2910THENUTL_RAW.CAST_TO_VARCHAR2(UTL_ENCODE.BASE64_ENCODE(DBMS_LOB.SUBSTR(EMPLOYEE_PHOTO, 1455, 1456)))
WHENDBMS_LOB.GETLENGTH(EMPLOYEE_PHOTO)<=2910ANDDBMS_LOB.GETLENGTH(EMPLOYEE_PHOTO)>1455THENUTL_RAW.CAST_TO_VARCHAR2(UTL_ENCODE.BASE64_ENCODE(DBMS_LOB.SUBSTR(EMPLOYEE_PHOTO, DBMS_LOB.GETLENGTH(EMPLOYEE_PHOTO)-1455, 1456)))
ENDAS C2,
CASE
WHENDBMS_LOB.GETLENGTH(EMPLOYEE_PHOTO)>4365THENUTL_RAW.CAST_TO_VARCHAR2(UTL_ENCODE.BASE64_ENCODE(DBMS_LOB.SUBSTR(EMPLOYEE_PHOTO, 1455, 2911)))
WHENDBMS_LOB.GETLENGTH(EMPLOYEE_PHOTO)<=4365ANDDBMS_LOB.GETLENGTH(EMPLOYEE_PHOTO)>2910THENUTL_RAW.CAST_TO_VARCHAR2(UTL_ENCODE.BASE64_ENCODE(DBMS_LOB.SUBSTR(EMPLOYEE_PHOTO, DBMS_LOB.GETLENGTH(EMPLOYEE_PHOTO)-2910, 2911)))
ENDAS C3,
CASE
WHENDBMS_LOB.GETLENGTH(EMPLOYEE_PHOTO)>5820THENUTL_RAW.CAST_TO_VARCHAR2(UTL_ENCODE.BASE64_ENCODE(DBMS_LOB.SUBSTR(EMPLOYEE_PHOTO, 1455, 4366)))
WHENDBMS_LOB.GETLENGTH(EMPLOYEE_PHOTO)<=5820ANDDBMS_LOB.GETLENGTH(EMPLOYEE_PHOTO)>4365THENUTL_RAW.CAST_TO_VARCHAR2(UTL_ENCODE.BASE64_ENCODE(DBMS_LOB.SUBSTR(EMPLOYEE_PHOTO, DBMS_LOB.GETLENGTH(EMPLOYEE_PHOTO)-4365, 4366)))
ENDAS C4,
CASE
WHENDBMS_LOB.GETLENGTH(EMPLOYEE_PHOTO)>7275THENUTL_RAW.CAST_TO_VARCHAR2(UTL_ENCODE.BASE64_ENCODE(DBMS_LOB.SUBSTR(EMPLOYEE_PHOTO, 1455, 5821)))
WHENDBMS_LOB.GETLENGTH(EMPLOYEE_PHOTO)<=7275ANDDBMS_LOB.GETLENGTH(EMPLOYEE_PHOTO)>5820THENUTL_RAW.CAST_TO_VARCHAR2(UTL_ENCODE.BASE64_ENCODE(DBMS_LOB.SUBSTR(EMPLOYEE_PHOTO, DBMS_LOB.GETLENGTH(EMPLOYEE_PHOTO)-5820, 5821)))
ENDAS C5
FROM PS_EMPL_PHOTO
WHERE EMPLID ='KUL704'

On the client I use something like this:

var data = data:image/jpeg;base64," + columns.join("");

The end result is something like this (right-click to see base64 data):

Mikko,Jill's Photo

Viewing all articles
Browse latest Browse all 201

Trending Articles