Forum Stats

  • 3,770,163 Users
  • 2,253,079 Discussions
  • 7,875,350 Comments

Discussions

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

User_ZH1UM
User_ZH1UM Member Posts: 3 Green Ribbon

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?