2 Replies Latest reply on Nov 2, 2012 1:58 PM by Justin Funk

    Problem displaying image blob from sync

      I have a Rails server that is storing images that I want to sync locally to my Rhomobile app through Rhoconnect.  I created a new source adapter in my Rhoconnect server to retrieve all the image information from the web server.  It first hits a json method to get the list of items in the database, and then iterates through each item to hit a second json service to get the list of images available for each item.  It then creates a new object with the parent item's id and properties for the various thumbnail sizes.  I then created the new model in the Rhomobile app and setup the blob properties for each of the various image sizes.  This all appeared to work correctly, as when I inspect the image object after sync, each of the properties is now a path to what looks like a local copy of the file, ex. [{:source_id=>21, :object=>"2", :item_id=>"8", :small_thumb_image_uri=>"/db/db-files/id_110220121611368746.jpg", :thumb_image_uri=>"/db/db-files/id_110220121611368867.jpg", :small_image_uri=>"/db/db-files/id_110220121611368474.jpg", :large_image_uri=>"/db/db-files/id_110220121611368615.jpg"}]. However, I am not then able to display the images to the page.  I get a 404 error.  Relevant code below:


      Rhomobile model:

      class ItemImage

        include Rhom::PropertyBag


        enable :sync


        property :small_thumb_image_uri, :blob

        property :thumb_image_uri, :blob

        property :small_image_uri, :blob

        property :large_image_uri, :blob



      Source adapater query:

        def query(params=nil)



          if items

            items.each do |item|

              item_id = item["item"]["id"].to_s

              images = JSON.parse(RestClient.get("#{@url}/items/#{item_id}/images.json?authentication_token=#{@auth}").body)

              if images

                images.each do |image|

                  key = image["id"].to_s

                  new_item = {

                    'item_id' => item_id,

                    'small_thumb_image_uri-rhoblob' => "#{@url}" + image["images"]["small_thumb"],

                    'thumb_image_uri-rhoblob' => "#{@url}" + image["images"]["thumb"],

                    'small_image_uri-rhoblob' => "#{@url}" + image["images"]["small"],

                    'large_image_uri-rhoblob' => "#{@url}" + image["images"]["large"],


                  @result[key] = new_item







      Sample of images.json result:




      <div data-role="page" data-add-back-btn="false">

        <div data-role="content">

          <ul data-role="listview">


                  <div class="itemValue"><%= @item.name %></div>


                <% @item_images.each do |item_image| %>


                <img src="<%= item_image.thumb_image_uri %>" /> 


                <% end %>