Idea Summary
Automatically remove the header part of Base64 encoded images if such exists data:image/png;base64,iVBORw0KG.… - in this example the data:image/png;base64,
Use Case
Very common use of APEX_WEB_SERVICE.CLOBBASE642BLOB is transforming Base64 encoded images into BLOBs. My experience shows that blobs get created corrupt (but without raising any error) if the header is included in the string. That's why currently I have to manually remove it before using the function to avoid bad blobs being created.
Preferred Solution (Optional)
If header of the Base64 string is present - trim it:
REGEXP_REPLACE(:P1_BASE64_IMG, '^data:[^;]+;base64,',‘’)
for example:
case when REGEXP_LIKE(:P1_BASE64_IMG, ‘^data:[^;]+;base64,’)
then REGEXP_REPLACE(:P1_BASE64_IMG, ‘^data:[^;]+;base64,’,‘’) --exists, trim it
else :P1_BASE64_IMG --not exists, leave it as is
end check_base64