Get canvas.toDataURL('image/jpeg') and convert base64 encoding to java.sql.Blob

Convert canvas.toDataURL('image/jpeg') to java.sql.Blob.
I am using oracle adf so I am able to action a backing bean from javascript and pass in parameters as a map. I pass in the canvas.toDataURL('image/jpeg') which I then try to decode in my bean. Using BASE64Decoder and the converting the bytearray to a file I can see the image is corrupted as I can't open the file thus converting the bytearray to blob is also a waste.
Has anyone any ideas on base64 encoding from canvas.toDataURL to file or Blob?

Use Case:
A jsf page that enables a user to take photos using the HTML5 canvas feature - interact with webcam -, take photos and upload to profile
1. I have created the jsf page with the javascript below; this pops up as a dialog and works okay and onclick an upload image, triggers the snapImage javascript function below and sends the imgURL parameter to the serverside managedbean
<!-- java script-->
function snapImage(event){
                var canvas = AdfPage.PAGE.findComponent('canvas');
                AdfCustomEvent.queue(event.getSource(),"getCamImage",{imgURL:canvas.toDataURL('image/jpeg'),true);
                event.cancel();
<!-- bean -->
public void getCamImage(ClientEvent ce){
String url=(String)ce.getAttributes().get("imgURL");
decodeBase64URLToBlob(url);
private BlobDomain decodeBaseB4URLToBlob(String url64){
                BASE64Decoder de=new BASE64Decoder();
                byte[] bytes=de.decode(url64);
                File file=new File("abc.jpg");
                InputStream in = new ByteArrayInputStream(bytes);
                BufferedImage bImageFromConvert = ImageIO.read(in);
                in.close();
                ImageIO.write(bImageFromConvert, "jpg", file);
                return createBlobDomainFromFile(file);
----problem---
Accessing the generated jpeg file shows the image is corrupted, probably missing bytes or encode/decoder issues.and the blob image after uploading to database is saved as a binary stream which ondownload doesnt render as an image or anything i know of.
Is there anyways of achieving the conversion without errors?

Similar Messages

  • Since Firefox 4, I can get a background image to work using base64 encoded, but not a local file, this worked in Firefox 3, how do I resolve this.

    Using either of the 4 examples shown below, to have a background image display inside about:blank worked in Firefox 3.x (using Stylish add-on), however since Firefox 4, only using the base64 encoded version of images works. Is there any way to fix this so I don't have to encode every image I wish to use? Encoding the image makes the stylish file absolutely huge, & a real pain to keep encoding whenever I want to change the image.
    body:empty { background: url("resource:/res/images/OnFire.jpg")
    body { background-image: url("resource:/res/images/OnFire.jpg")
    body:empty { background:url("data:
    body { background-image: url("data:
    I've also previously disabled most of the add-ons, except for Status-4-Evar, Stylish, & Firebug, in an attempt to see if something else was interfering, but no change.
    I can supply a copy of the previously working (FF 3.x) code to some of the about:blank styles if needed for testing purposes.

    Type '''about:addons'''<enter> in the address bar to open the '''Add-ons Manager.'''
    Hot key; '''<Control>''(Mac:<Command>)'' <Shift> A)'''
    On the left side of the page, select '''Plugins.'''
    Is it listed here? Select '''Disable.'''

  • Converting Base64 encoded String to String object

    Hi,
    Description:
    I have a Base64 encoded string and I am using this API for it,
    [ http://ws.apache.org/axis/java/apiDocs/org/apache/axis/encoding/Base64.html]
    I am simply trying to convert it to a String object.
    Problem:
    When I try and write the String, ( which is xml ) as a XMLType to a oracle 9i database I am getting a "Cannot map Unicode to Oracle character." The root problem is because of the conversion of the base64 encoded string to a String object. I noticed that some weird square characters show up at the start of the string after i convert it. It seems like I am not properly converting to a String object. If i change the value of the variable on the fly and delete these little characters at the start, I don't get the uni code error. Just looking for a second thought on this.
    Code: Converting Base64 Encoded String to String object
    public String decodeToString( String base64String )
        byte[] decodedByteArray = Base64.decode( base64String );
        String decodedString = new String( decodedByteArray, "UTF-8");
    }Any suggestions?

    To answer bigdaddy's question and clairfy a bit more:
    Constraints:
    1. Using a integrated 3rd party software that expects a Base64 encoded String and sends back a encoded base64 String.
    2. Using JSF
    3. Oracle 10g database and storing in a XMLType column.
    Steps in process.
    1. I submit my base64 encoded String to this 3rd party software.
    2. The tool takes the encoded string and renders a output that works correctly. The XML can be modified dynamically using this tool.
    3. I have a button that is binded to my jsf backing bean. When that button is clicked, the 3rd party tool sets a backing bean string value with the Base64 String representing the updated XML.
    4. On the backend in my jsf backing bean, i attempt to decode it to string value to store in the oracle database as a XML type. Upon converting the byte[] array to a String, i get this conversion issue.
    Possibly what is happen is that the tool is sending me a different encoding that is not UTF-8. I thought maybe there was a better way of doing the decoding that i wasn't looking at. I will proceed down that path and look at the possibility that the tool is sending back a different encoding then what it should. I was just looking for input on doing the byte[] decoding.
    Thanks for the input though.
    Edited by: haju on Apr 9, 2009 8:41 AM

  • Convert a String to java.sql.Date Format

    Hi,
    I am having a String of containing date in the format 'dd/mm/yyyy' OR 'dd-MMM-YYYY' OR 'mm-dd-yyyy' format. I need to convert the string to java.sql.Date object so that I can perform a query the database for the date field. Can any one suggest me with the code please.
    Regards,
    Smitha

    import java.text.SimpleDateFormat;
    import java.text.ParseException;
    import java.util.Date;
    public class TestDateFormat
         public static void main(String args[])
              SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
              System.out.println(sdf.isLenient());
              try
                   Date d1 = sdf.parse("07-11-2001");
                   System.out.println(d1);
                   Date d2 = sdf.parse("07:11:2001");
                   System.out.println(d2);
              catch(ParseException e)
                   System.out.println("Error format, " + e);
    See class DateFormat and SimpleDateFormat for detail.

  • Datasource, POJO and java.sql.Blob

    Hello,
    is "java.sql.Blob" a valid type for a POJO datasource ?
    I declared one but I just dit not succeed in rendering its jpg picture.
    My java code is quite simple :
    ReportClientDocument reportClientDocument = new ReportClientDocument ();
    reportClientDocument.setReportAppServer(ReportClientDocument.inprocConnectionString);
    reportClientDocument.open (REPORT_NAME, OpenReportOptions._openAsReadOnly);
    // lBlob is a class which implements java.sql.Blob interface
    LPOJOData [] dataP = {new LPOJOData(new lBlob("Picture.jpg"))};
    POJOResultSetFactory factory = new POJOResultSetFactory(LPOJOData.class);
    POJOResultSet resultSet = factory.createResultSet(dataP);
    reportClientDocument.getDatabaseController().setDataSource(resultSet, "", "");
    and my POJO class :
    public class LPOJOData {          
              private java.sql.Blob zimage;
              public LPOJOData(java.sql.Blob zp){
                   this.zimage = zp;
              public java.sql.Blob getzimage(){
                   return zimage;
    The field "zimage" on the report is designed through a "field definition only" database, zimage is defined as a Blob field.
    Any clues ?
    Regards,
    Serge

    I have just found a list of the data types supported by a POJO Class :
    # boolean
    # byte
    # char
    # double
    # float
    # int
    # short
    # java.lang.Boolean
    # java.lang.Byte
    # java.lang.Double
    # java.lang.Float
    # java.lang.Integer
    # java.lang.Short
    # java.lang.String
    # java.SQL.Date
    # java.SQL.Time
    Well, java.SQL.Blob is not one of them.
    Is java.SQL_Blob will be a valid POJO type in the future ?
    Is there another way than POJO to feed a report from an in-memory datasource ?

  • Creating/constructing a java.sql.Blob and writing to Oracle with jdbc

    I'm trying to understand how to create a blob from an image file to write it to a Oracle database using jdbc.
    I know there'a a getBinaryStream method in java.sql.Blob to which I can write the files byte array, but how do I create an actual blob in the first place. All examples I've seen initialise the blob from an exiting Blob field in a database which I do not have filled yet
    thanks

    In general, you will do something like the following:
    Ensure setAutoCommit is false
    INSERT INTO foo (blob_column) values (empty_blob());
    SELECT blob_column FROM foo FOR UPDATE;
    Call getBlob() on the ResultSet
    Cast it to Oracle's specific BLOB (different object)
    Call getBinaryOutputStream() on the BLOB
    Pipe your data
    Commit (very importatnt as FOR UPDATE will lock that row)- Saish

  • Images downsized and converted when exporting to PDF

    I have Pagemaker 7.0.1 installed on Virtual XP so that I can help out a family member.
    Pagemaker's embedded Acrobat 4 was not working properly so I installed my Acrobat 9.0 on Virtual XP. This unfortunately has not solved the problem, which is:
    My images are greyscale and 300 ppi when imported into Pagemaker. When exported to PDF using Acrobat 9.0, the images are being converted to CMYK and exported at about 50% of the actual size. Interestingly, those images that are only at 200 ppi are converted but not downsampled.
    This is happening no matter how I fiddle with the settings. Happens to both jpegs and tiffs.
    I found an old thread on another forum where this problem occurred but a solution was not found or posted.
    Any ideas?
    Michelle

    This reply is a series of comments and suggestions rather than a definitive answer.
    1. Your set up is less than perfect, if not unstable, and will be prone to all sorts of bizarre behaviours.
    2. Never copy/paste a graphic or table into PageMaker.  Always use the Place command. The only "exception" would be that you can copy and paste a properly Placed graphic from within your PageMaker document.
    When placing images in a PageMaker file, the following message appears: “The graphic in the linked file would occupy xxxxxxx bytes in the publication. Include the complete copy in the publication anyway?” The correct answer to this question is always "NO".
    (You can permanently avoid this popup in future docs by unchecking "store copy in publication" under Element -> Link Options with no publication open. You can do the same to avoid further prompts in pre-existing documents.)
    3. Try updating PM to Ver 7.0.1a which had a better Export… AdobePDF…macro. http://www.adobe.com/support/downloads/product.jsp?product=34&platform=Windows 
    4. In PageMaker’s Print dialogue, click on the Options button, and check "Write PostScript to File." Select the "Normal" radio button. Set both Type 1 and TrueType fonts to download. As always, set the Send TIF/Images option to Normal and NOT Optimized. Make other settings elsewhere in the print dialog as desired, such as "paper" size, crop marks, separations, etc.
    5. With your non-standard setup, try the two stage print then distill process. Create a PS file using a postscript printer file, then load Distiller and convert the PS file to PDF.  Note: if you have hyperlinks in your PMD file, they will not appear in your PDF and need to be re-created using Acrobat.
    6. It's time to leave PM and move on to InDesign - see it as PM Ver 13. 
    7. Aternatively, use PM7 on a contemporary Win2K PC.  http://bigjohnd.org.uk/PageMakerExportPDF/index.htm

  • Image size and mime type.. non-java guy needs help

    Image size, mime type.. non-java guy needs help
    Im not at all familiar with java so this is really weird for me to work out. I?ve been doing it all day (and half of yesterday).
    Im trying to write a custom clodFusion tag in java that gets the width, height, size and MIME types of a given file. I?ve been trying to get it to work on the command line first. I can get the width and height but cant get the size and the MIME type.
    Here is what I got
    /*import com.allaire.cfx.*;*/
    import java.awt.image.renderable.*;
    import javax.media.jai.*;
    import com.sun.media.jai.codec.*;
    import java.io.*;
    import java.util.*;
    public class ImageInfo {
    private RenderedOp image = null;
    private RenderedOp result = null;
    private int height = 0;
    private int width = 0;
    private String type = "";
    private String size = "";
    public void loadf(String file) throws IOException
    file = "80by80.jpg";
    FileSeekableStream fss = new FileSeekableStream(file);
    image = JAI.create("stream", fss);
    height = image.getHeight();
    width = image.getWidth();
    System.out.println(height + "\n");
    System.out.println(width);
    System.out.println(type);
    public static void main(String[] args) throws IOException {
    ImageInfo test = new ImageInfo();
    test.loadf(args[0]);
    can anyone please help me out to modify the above so I can also print the mime type and the file size to screen.
    thanks for any help

    any suggestions?

  • How to convert String date to java sql date

    I have an html form for entering the Date on retreving that value in a java servlet i get it as a string i want to convert that date to SQL date format so that i could use setDate() method of the java.sql.Date class to update the date value in the database.
    i used the following way but i need the code without using the deprecated ones.
    String delDate = (String)p_Request.getParameter("deleteDate");
    [b]java.util.Date utilDate = new java.util.Date(delDate);
    java.sql.Date deleteDate = new java.sql.Date(utilDate.getTime());
    custCode = (String)p_Request.getValue("custCode");
    thanx in advance.

    Check out the later posts in http://forum.java.sun.com/thread.jspa?threadID=647681&messageID=3814745#3814745

  • Converting String to Date (java.sql.date)

    Hi,
    Kindly let me know how I can convert a string like
    "20061102" (YYYYMMDD) to a Date type (java.sql.date) in web Dynpro.
    Requirement is to set a DateType context Attribute with
    the value contained in the String ("20061102" ).
    Awaiting your kind responses..
    Regards,
    Mahesh

    SimpleDateFormat yyyyMMdd_parser = new SimpleDateFormat(
                   "yyyyMMdd");
    java.util.Date date=yyyyMMdd_parser.parse("20061102");
    java.sql.Date slqDate=new java.sql.Date(date.getTime());

  • Can one get a split image (Before and After) whilst using Color Board?

    The basic way of comparing the effect of a color correction appears to be to step out of the Color Board and switch the correction off and on.
    However, is there any way of displaying 2 screens (or a split screen) showing the original shot and the corrected one? (I seem to vaguely recollect having something like that in FCP 7, though it may not have been in conjunction with color correction  .  .  .  my memory!)

    You could also toggle the correction off and on with a keyboard shortcut Control-1 I think. Indeed how quickly we forget.

  • Convert Base64 encoded message into string

    Hello Experts,
    I have an outlook message(text+image) which is encoded in base 64. I need to convert it into string(readable text).
    Do we have any FMs for this conversion.
    Thanks,
    Suman

    [Base64 decoding|http://wiki.sdn.sap.com/wiki/display/Snippets/DecodingBASE64in+ABAP]
    Search SCN first, you just might get lucky.

  • Get Unix disk space available and assign it to a pl/sql variable

    Hello,
    From withint pl/sql, how do I get disk space(df -k) vailable from the os and assign that number to a pl/sql variable? I want to write a stored procedure that will look into how much space left on a os mount point. Thank you.

    You can check this thread
    http://asktom.oracle.com/pls/ask/f?p=4950:8:13164696856450032216::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:952229840241

  • Convert a string to JAva.sql.date..

    I am having a string with the value as follows..
    String fval="03-10-2001"..
    I am using this value in a rs.updateDate method where I need to convert it to a different format as
    2001-10-03...can anybody give me the syntax..

    You should hold dates as Date instances. But if you want to convert between Strings and Dates then you should use a DateFormat:
    String originalDateString = "31-10-2001";
    // Convert the original string to a date
    DateFormat originalDateFormat = new SimpleDateFormat("dd-MM-yyyy");
    Date date = originalDateFormat.parse(originalDateString);
    // Get a representation of the date in the new format
    DateFormat newDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    String newDateString = newDateFormat.format(date);(Excuse the quirky formatting that the Java code filter applies!)
    Hope this helps.

  • Convert Canvas to Image in sapui5

    Convert canvas to image using controller in sapui5,I have tried these codes but nothing works..Please help me.
    Here is my code:
    onOkCloseButton : function(oEvent) {
      var view = this.getView();
      var canvas = view.byId("canvas");
    var dataURL = canvas.toDataURL("image/png");
    // var window = window.open();
    // window.document.write('<img src="'+dataURL+'"/>');
    // window.location = (canvas.toDataURL('image/png'));
    // var dataURL = canvas.toDataURL();
    // $.post("http://localhost:31651/Registration_Card/index.html", { img : canvas.toDataURL() }) 
    // .done(function(data) { 
    //  alert("Image Sent to Server "); //on completion 
    // Canvas2Image.saveAsJPEG(canvas);
    // var oImgJPEG = Canvas2Image.saveAsJPEG(canvas, true);
    // Canvas2Image.saveAsPNG(canvas, false, 100, 100);
      oEvent.getSource().getParent().close();

    Ho to save a canvas as an image in J9 and CDC.
    It seems that I already have resolute by means of the tool Jimi de Sun. Anyway I will thank for any new contribution.
    Thanks

Maybe you are looking for

  • Period Incorrect Setup

    Hi Experts. Our client is running SBO 2007A SP00 PL45. Their financial year runs from 1st January to 31st December. They have incorrectly setup 2010 as a single period instead of 12 calendar months. They have entered transactions into this period and

  • Found a new use for my iPad

    No not as a paper weight I can now watch normal free to air TV on my iPad over my wifi anywhere in range. I bought an Avermedia HD Homefree Duet. You plug your TV antenna into it and connect it to your router via ethernet. The Homefree app is availab

  • New message font

    I have my mail Font Settings set to Calibri 13 for new messages. However when I receive the message in Outlook on my Windows PC the font is changed to Times New Roman and the point size is changed to 12. I can send messages in Calibri on my PC and I

  • Delete and getbykey in udo

    I have created a form using udo.How to add delete option on the right click  on the form ? I have created udo using following code- objFields.TableName = "@QCRF1"             objFields.Name = "Entry_No"             objFields.Type = SAPbobsCOM.BoField

  • My first Java Program

    I will be taking Java in School in a couple of months. I thought it would be a good idea to start trying it out now. One of the books I am reading has this example problem. It basically wants you to draw a hollow square 5 by on the screen. It says to