def download_image_from_server # Get the album id from local db album_record = Album.find(@params["album_id"]) if album_record album_id = album_record.id # call the api to get the image path result = Rho::AsyncHttp.get( :url => "some_domain.com/images.json?album_id=#{album_id}", :authentication => { :type => :basic, :username => $username, :password => $password } ) if result["status"].upcase == "OK" && result["body"] !="" images = result["body"] download_failed_number = 0 images.each do |image|image_name = image["image_name"] image_path = image["image_path"] # Prepare the full path of image to be stored after download image_blob_path = File.join(Rho::RhoApplication::get_blob_folder(), image_name) download_result = Rho::AsyncHttp.download_file ( :url => "some_domain.com/" + image_path, :filename => image_blob_path, :headers => {} ) if download_result["status"].upcase == "OK" download_failed_number += 1 end end return true else return false end end end
Note:: Now the image has been downloaded to the applications internal memory for using in the application. If we want to store that image to some other location, we just need to do a file operation by reading the content of the image as binary data and append the contents to a new file on other location.