Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Resize Blob to smaller Blob

Hawk333Jan 30 2015 — edited Feb 3 2015

I'm using the following script to do that;

  1. declare 
  2. obj ordsys.ordimage; 
  3. b blob; 
  4. begin  
  5. select photo into b from sync_photos where PHOTO_ID = 7585; 
  6. obj := ordsys.ordimage( ordsys.ordsource( b, null, null, null, sysdate, 1 ), 
  7. null, null, null, null, null, null, null ); 
  8. obj.setProperties(); 
  9. obj.process('maxScale=32 32'); 
  10. b := obj.getContent(); 
  11. update sync_photos 
  12. set BLOB_THUMB = b 
  13. where PHOTO_ID = 7585; 
  14. 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

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 3 2015
Added on Jan 30 2015
4 comments
1,393 views