2 Replies Latest reply on Apr 9, 2014 1:12 PM by Mark Ross

    Ability to sync blobs using javascript ORM model

      Hi,

       

      I have a javascript ORM model with one of the properties is declared as blob ( please see below for orm definition).

       

         Rho.ORM.addModel(function(model) {

              model.modelName('BinaryAttachments');

              model.property('name','string');

              model.property('databasePrimaryKey','string');

              model.property('docId','string');

              model.property('orId','string');

              model.property('plant','string');

              model.property('synced','string');

              model.property('image_uri','blob');

              model.property('attachment','string');

              model.set("partition","user");

              // optionally enable sync for rhoconnect applications

              model.enable('sync');

              // optionally, define the model as fixed schema default is propertyBag

              // model.enable('fixedSchema');

          });

       

      The source adapter is in ruby. The following method is not getting invoked. Per documentation this method will get invoked when rhconnect identifies something as blob. In my case this method is not getting invoked at all.

       

      def store_blob(object,field_name,blob)

          puts " hydro store store blob  "

          puts field_name

          puts blob[:filename]

          # TODO: Handle post requests for blobs here.

          # make sure you store the blob object somewhere permanently

          #raise "Please provide some code to handle blobs if you are using them."

          #my_stored_filename = do_custom_store[blob[:filename]]

          #obj['filename'] = my_stored_filename

          obj['filename'] = blob[:filename]   

        end

       

      And then when create is invoked the file is not there as it is still pointing to file on the device.

       

      Question here is, is there support for blobs when model is created in javascript ( in my case source adapter is in ruby - primarily because we are deploying rhoconnect in weblogic and did not want to deal with node.js).

       

      Thanks,

      Prasad

        • Re: Ability to sync blobs using javascript ORM model

          Hi,

           

          Could you walk through the steps you use a little bit more?

           

          1) Create a new BinaryAttachments record after your camera callback is executed in javascript and save it (DB snapshot #1)

          2) Call RhoConnectClient.doSync()    (DB snapshot #2)

          3) At this point your rhoconnect server should receive a POST request (visible in the logs) and your store_blob method in your source adapter model should be executed.

          4) Next you should see a GET request in the rhoconnect server logs as the client will download backend changes (your source adapter model query method should be executed).  Make sure your query method updates the blob attribute (see the sample code here: http://docs.rhomobile.com/en/4.0.0/rhoconnect/blob-sync )  (DB snapshot #3)

          5) Now your local copy of the record (make sure you fetch again from the database via the `find` method: http://docs.rhomobile.com/en/4.0.0/api/OrmModel#mfind ) should have a URL for 'image_uri' model property.  This assumes you set it to a URL (i.e. http://example.com/mypicture.png) in your source adapter model's query method from step #4.

           

          If you're using rhosimulator, you can create copies of the rhosimulator/db/syncdbuser.sqlite file where I mentioned DB snapshot #1, #2, #3, respectively.  This will help with understanding what is going on at each stage of the blob sync process.

          • Re: Ability to sync blobs using javascript ORM model
            Mark Ross

            Prasad,

             

            Did you ever figure this out?  I feel like I'm running into the same issue.  My storeBlob method in my source adapter (mine is actually in javascript using node) is never called.  I have the nearly the same javascript Rho model defined (with one model.property set to 'blob').  I can see from the logs that the 'create' source adapter method is being called as the POST is happening after I issue a Rho.RhoConnectClient.doSyncSource('mymodel').  But I never get any log output from my storeBlob method.  So Lars' step #3 doesnt seem to be happening.  If you or Lars would like example code, I'm happy to post it.

             

            -Mark