I'm using the following script to do that;
- declare
- obj ordsys.ordimage;
- b blob;
- begin
- select photo into b from sync_photos where PHOTO_ID = 7585;
- obj := ordsys.ordimage( ordsys.ordsource( b, null, null, null, sysdate, 1 ),
- null, null, null, null, null, null, null );
- obj.setProperties();
- obj.process('maxScale=32 32');
- b := obj.getContent();
- update sync_photos
- set BLOB_THUMB = b
- where PHOTO_ID = 7585;
- end
However, the resultant Blob causing errors when I encode to Base64. The original BLOB can be encoded to Base64 without any problem, but when I encode the resultant Blob (the smaller one), I get the response from MongoDB (I'm trying to send image from Oracle DB to Appery (MongoDB) : "serialization error" which is the error I usually get with the content is corrupted. I can see the resultant blob is blurred but still an image and I expect to be transferred to MongoDB.
The following the function I use to encode to Base64:
FUNCTION base64encode(
p_blob IN BLOB)
RETURN CLOB
IS
l_clob CLOB;
l_step PLS_INTEGER := 12000; -- make sure you set a multiple of 3 not higher than 24573
BEGIN
FOR i IN 0 .. TRUNC((DBMS_LOB.getlength(p_blob) - 1 )/l_step)
LOOP
l_clob := l_clob || regexp_replace(UTL_RAW.cast_to_varchar2(UTL_ENCODE.base64_encode(DBMS_LOB.substr(p_blob, l_step, i * l_step + 1))), '[[:space:]]',null); --remove newline characters
END LOOP;
RETURN l_clob;
END;
Ultimately, what I'm trying to do is to send images from Oracle DB to MongoDB, but the size of images in Oracle DB is fairly big (of MB's), while images stored in Mobile App (linked to MongoDB) is just about 20~30KB. So I need to resize before I send them. If I keep the same size (2MB), it takes hours for the base64encode function above to convert them and still running.
Any advice would be deeply appreciated