【问题标题】:Fetching images binary data from the CRML从 CRML 获取图像二进制数据
【发布时间】:2017-04-20 20:43:49
【问题描述】:

尝试从 CRML 媒体资源中获取 :all(第一个 :item)。使用 Estately RETS 回购。这是我的 ruby​​ 示例文件:

require 'rets'

client = Rets::Client.new({
  login_url: 'url',
  username: 'user',
  password: 'password',
  version: 'RETS/1.7.2' 
})

begin
    client.login
rescue => e
    puts 'Error: ' + e.message
    exit!
end

puts 'We connected! Lets get all the photos for a property...'


photos = client.find (:first), {
  search_type: 'Media',
  class: 'Media',
  query: '(MediaModificationTimestamp=2017-04-15+),(MediaType=Image)'
}


photo = open(photo = photos['MediaURL'])
require 'base64'
image = Base64.encode64(photo.read)


File.open('property-1.gif', 'wb') do|f|
  f.write(Base64.decode64(image))
end

puts photos.length.to_s + ' photos saved.'
client.logout

但我只得到一张图片,而不是预期的 26 张。在我得到第一个工作之后,也不确定这是否是检索所有列表的所有图像的最佳方法。这是有关此问题的更多信息https://github.com/estately/rets/issues/210

【问题讨论】:

    标签: ruby rets phrets mls


    【解决方案1】:
    require 'rets'
    
    client = Rets::Client.new({
      login_url: 'url',
      username: 'username',
      password: 'password',
      version: 'RETS/1.7.2' 
    })
    
    begin
        client.login
    rescue => e
        puts 'Error: ' + e.message
        exit!
    end
    
    puts 'We connected! Lets get all the photos for a property...'
    
    
    photos = client.find (:all), {
      search_type: 'Media',
      class: 'Media',
      query: '(ResourceRecordKeyNumeric=117562969),(MediaType=Image)'
    }
    
    photos.each_with_index do |data, index|
      photo = open(photo = data['MediaURL'])
      puts data['MediaURL']
      require 'base64'
      image = Base64.encode64(photo.read)
      File.open("property-#{index.to_s}.jpg", 'wb') do |f|
        f.write(Base64.decode64(image))
      end
    end
    
    
    puts photos.length.to_s + ' photos saved.'
    client.logout
    

    【讨论】:

      【解决方案2】:

      您可以尝试在查询部分中使用逗号分隔的列表 ID 以一次获取多个列表的所有图像。

      photos = client.find (:all), {
      search_type: 'Media',
        class: 'Media',
        query: '(ResourceRecordKeyNumeric=117562969,117562970,117562971),(MediaType=Image)'
      }
      

      【讨论】:

        猜你喜欢
        • 2012-08-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-03-12
        • 1970-01-01
        • 2015-09-10
        • 1970-01-01
        相关资源
        最近更新 更多