Is it possible to store images in datastore? I want to cache some images for offline viewing.

  • what solution did you end up using?
    – Phil B
    Jun 11, 2014 at 20:56

2 Answers 2


A better place to store images is the filesystem of the device. You can do this via the Cordova File functionality, documented at:


Raymond Camden wrote a couple of blog posts that demonstrate how to store images locally for Android and iOS.

Blog 1

Blog 2

  • Would this be considered secure storage?
    – Phil B
    Jun 11, 2014 at 20:23

Yes we can securely store images in smart store. steps to implement:

1)Create soup:

 navigator.smartstore.registerSoup('ImageStore', indexSpecs, successCallback, errorCallback);

2)Configure Cordova Camera plugin:

Configure camera return option as DATA_URL to get result as base64.

navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
        destinationType: Camera.DestinationType.DATA_URL });
    function onSuccess(imageData){
        //Once we get the base64, simply store it in app's smart store.
        var temp = new Object();
        temp.Base64 = "data:image/jpeg;base64," + imageData;
        temp.ParentId = parentId; //parent record Id
        navigator.smartstore.upsertSoupEntries('ImageStore', [temp], function(data){
                console.log('image cached successfully');    

3)Store base64 string into smart store and upload it to cloud if needed As we know salesforce mobilesdk's smart store encrpytes its data. Also for cloud sync, its easy to query base64 string and upload it to salesforce.

var querySpec = navigator.smartstore.buildExactQuerySpec("ParentId", parentId);
        navigator.smartstore.querySoup('ImageStore', querySpec, function(response){
                var data = response.currentPageOrderedEntries[0]; 
        function createAttachment(data){
                function (dataResponse) {
                    console.log('Attached successfully');

In this approach third party apps not able to see our captured image. Let me know if you have any other questions.

Ref : Smartstore Documentation https://developer.salesforce.com/docs/atlas.en-us.mobile_sdk.meta/mobile_sdk/offline_soup.htm

Camera plugin https://github.com/apache/cordova-plugin-camera

  • This is not really an answer. Can you please add examples, detail to it? Otherwise, it might get removed as a non-response. Jul 26, 2016 at 15:06
  • 1
    @HariHaraSuthan Could you add more details to your answer please. This is a two year old question that you've just posted an answer to, so it appears out of context and you've not told us how you'd do what you describe. I'm confident that methods available 2yrs ago are quite different than what's available now.
    – crmprogdev
    Jul 26, 2016 at 15:39
  • @HariHaraSuthan Please edit your question rather than adding it in comments. Jul 27, 2016 at 7:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .