`
tx984471
  • 浏览: 38791 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

如何显示sqlserver中image字段类型的图片

    博客分类:
  • ROR
阅读更多
我现在在ruby中已经把图片保存到数据库中,但是读不出来,
我是这样写的
def picture
      @rypicture = RyPicture.find(params[:id])
      send_data(@rypicture.data,
                :filename => @rypicture.name,
                :type => @rypicture.content_type,
                :disposition => 'inline')
    end

在show界面上该如何写呢?
分享到:
评论
1 楼 tx984471 2008-05-16  
已经解决。
保存地址,读数据时引用地址。
这样不保存在数据库里比较好,避免了影响数据库性能。
在activerecord里写
  def picture=(picture_field)
    self.name = base_part_of(picture_field.original_filename)
    self.content_type = picture_field.content_type.chomp
    #self.data = picture_field.read
    self.image_url = "/images/" + self.name
   
    File.open("#{RAILS_ROOT}/public/images/#{picture_field.original_filename}", "wb+") do |f|
    f.write(picture_field.read)
    end
  end

  def base_part_of(file_name)
    File.basename(file_name).gsub(/[^\w._-]/, '')
  end
其他地方正常处理就可以了

相关推荐

Global site tag (gtag.js) - Google Analytics