Topic
3 replies Latest Post - ‏2013-01-29T04:25:40Z by pandrbox
pandrbox
pandrbox
22 Posts
ACCEPTED ANSWER

Pinned topic Bitmap resources as local dynamic data

‏2013-01-28T09:59:57Z |
When bitmap resources are displayed on application screen, they must be on the folder under /common or HTTP access from web.

I'd like to download resources from Worklight server or web server then store them on the device local storage like JSONStore.

Is it possible to store bitmap binary data on device storage and display it on the screen ? How can I do this ?
  • SystemAdmin
    SystemAdmin
    2327 Posts
    ACCEPTED ANSWER

    Re: Bitmap resources as local dynamic data

    ‏2013-01-28T15:06:12Z  in response to pandrbox
    JSONStore is a JavaScript API and to the best of my knowledge there is no way to handle binary data in JavaScript without converting it something like base64. You can store base64 text inside JSONStore, but not binary data (think NSData in Objective-C or Byte Array in Java).

    Here's a link to get you started if you want to encode/decode base64:
    http://stackoverflow.com/a/246813/186909

    We also ship with SJCL (I'm not sure if that will change in the future), but now you can do:

    
    var encodeBase64 = function (input) 
    { var bits = sjcl.codec.utf8String.toBits(input); 
    
    return sjcl.codec.base64.fromBits(bits); 
    }   var decodeBase64 = function (input) 
    { var bits =  sjcl.codec.base64.toBits(input); 
    
    return sjcl.codec.utf8String.fromBits(bits); 
    }
    


    You can read about SJCL here:
    https://crypto.stanford.edu/sjcl/

    Fair warning: I did not test de code above, just looked at the API and made functions.

    Regarding how you would use JSONStore:

    
    collection.store(
    {img: [base64 representation]
    });
    


    Where collection is a JSONStore Instance object, what you get after calling initCollection(...).
    http://pic.dhe.ibm.com/infocenter/wrklight/v5r0m5/index.jsp?topic=%2Fcom.ibm.worklight.help.doc%2Fapiref%2Fr_class_wl_jsonstore.html
    • SystemAdmin
      SystemAdmin
      2327 Posts
      ACCEPTED ANSWER

      Re: Bitmap resources as local dynamic data

      ‏2013-01-28T15:44:53Z  in response to SystemAdmin
      Or you could use image to base 64 string such as http://webcodertools.com/imagetobase64converter. Then use This is a sample to put image into screen...

      Jerry
  • pandrbox
    pandrbox
    22 Posts
    ACCEPTED ANSWER

    Re: Bitmap resources as local dynamic data

    ‏2013-01-29T04:25:40Z  in response to pandrbox
    Thank you, that's exactly what I want to do. The sample you have put on the comment works on Firefox but doesn't work on Safari unfortunately. I need to check on iOS.