Skip to Main Content

APEX

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!

Why is it that my images is a .png instead of a .jpg?

User_ZH1UMSep 13 2021

I have the following pl/sql code in an Ajax Callback which takes the blob content from a table and converts into (clob)base64:
declare
l_photo_clob clob;
l_photo_blob blob;
begin
select BLOB_CONTENT
into l_photo_blob
from UPLOADED_IMAGES
where FILENAME = :P1_IMAGES;

l_photo_clob := apex_web_service.blob2clobbase64(
p_blob => l_photo_blob
);

apex_json.open_object;
apex_json.write('photoBase64', l_photo_clob);
apex_json.close_object;
end;

I then take the the generated base64 encode clob and use it as the image source to draw the image to a canvas:
apex.server.process(
"get_image",
{},
{
success: async function(data) {
const imageSize = 224;
var canvas = document.getElementById("canvas");
canvas.width = imageSize;
canvas.height = imageSize;
var ctx = canvas.getContext("2d");

            var imageBLOB = new Image();  

            imageBLOB.onload = function() {  
                ctx.drawImage(imageBLOB, 0, 0,  imageSize, imageSize);  
                var imgData = ctx.getImageData(0, 0, imageSize, imageSize);  
                readImage(imgData.data);   
            };  
            imageBLOB.src = "data:image/jpeg;base64," + data.photoBase64;  
            imageBLOB.crossOrigin = "Anonymous";  
        }  
    }  
);  

I would have thought that "data:image/jpeg;base64," would have defined the image as a jpg/jpeg, however when I right click on the image it is saved as a .png and not .jpg/jpeg. I've looked at the documentation for "apex_web_service.blob2clobbase64", and they is no way that I'm seeing to include the mime type in the conversion. Is they another way I should be doing this so that the mime type is preserved?

Comments
Post Details
Added on Sep 13 2021
0 comments
1,113 views