paperclip-qiniu

使用七牛云上传静态资源

paperclip-qiniu
https://github.com/lidaobing/paperclip-qiniu/

gem 'paperclip'
gem 'paperclip-qiniu'
# application.yml

QINIU_ACCESS_KEY: xxxxx
QINIU_SECRET_KEY: xxxxx
QINIU_HOST: 'xxxx'
QINIU_BUCKET: 'xxx'
# config/initializers/paperclip.rb

Paperclip::Attachment.default_options[:storage] = :qiniu
Paperclip::Attachment.default_options[:qiniu_credentials] = {
  :access_key => ENV['QINIU_ACCESS_KEY'] || raise("set env QINIU_ACCESS_KEY"),
  :secret_key => ENV['QINIU_SECRET_KEY'] || raise("set env QINIU_SECRET_KEY")
}
Paperclip::Attachment.default_options[:bucket] = 'paperclip-qiniu-example'
Paperclip::Attachment.default_options[:use_timestamp] = false
Paperclip::Attachment.default_options[:qiniu_host] =
  'http://cdn.example.com'
# model

class Image < ActiveRecord::Base
  attr_accessible :file
  has_attached_file :file, :path => ":class/:attachment/:id/:basename.:extension"
  validates :file, :attachment_presence => true
  validates_attachment_content_type :file, :content_type => /\Aimage\/.*\Z/
end
# view

<%= qiniu_image_tag @image.file.url, :thumbnail => '300x300>', :quality => 80 %>
or
<%= image_tag qiniu_image_path(@image.file.url, :thumbnail => '300x300>', :quality => 80) %>

相关参考:
http://paperclip-qiniu-example.herokuapp.com/

Deleting an Attachment (删除图片文件)
Set the attribute to nil and save.
@user = User.find id
@user.avatar = nil
@user.save

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<div v-else-if="per.dict_value === 'file_name'"> <el-tooltip placement="top" effect="dark" v-if="scope.row.download_time || scope.row.repair_download_time"> <div slot="content" > <span v-if="scope.row.repair_download_time">{{ parseTime(scope.row.repair_download_time,'{y}-{m}-{d} {h}:{i}:{s}') }}</span> <span v-else-if="scope.row.download_time">{{ parseTime(scope.row.download_time,'{y}-{m}-{d} {h}:{i}:{s}') }}</span> </div> <el-link v-if="scope.row.repair_file_id" :key="scope.row.repair_file_id" style="display: block;color: #67C23A" icon="el-icon-paperclip" @click="downloadOrderExcel(scope.row.repair_file_id, scope.row.order_no, scope.row.repair_file_name)" >{{ scope.row.repair_file_name }}</el-link> <el-link v-else-if="scope.row.file_id" :key="scope.row.file_id" style="display: block;color: #67C23A" icon="el-icon-paperclip" @click="downloadOrderExcel(scope.row.file_id, scope.row.order_no, scope.row.file_name)" >{{ scope.row[per.dict_value] }}</el-link> </el-tooltip> <div v-else> <el-link v-if="scope.row.repair_file_id" :key="scope.row.repair_file_id" style="display: block;" icon="el-icon-paperclip" @click="downloadOrderExcel(scope.row.repair_file_id, scope.row.order_no, scope.row.repair_file_name)" >{{ scope.row.repair_file_name }}</el-link> <el-link v-else-if="scope.row.file_id" :key="scope.row.file_id" style="display: block;" icon="el-icon-paperclip" @click="downloadOrderExcel(scope.row.file_id, scope.row.order_no, scope.row.file_name)" >{{ scope.row[per.dict_value] }}</el-link> </div> </div>优化这段代码用vue2.0
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值