Chỉ cần thêm khả năng tải trực tiếp lên Amazon S3 bằng đá quý s3_direct_upload.Kẹp giấy: tùy chọn kiểu không hoạt động với s3_direct_upload
Thật không may, bây giờ nó không xử lý hình ảnh bổ sung thay đổi kích thước mà tôi có như thế này.
:styles => { :thumbnail => "200x200#" }
Sau khi xem tài liệu, tôi không thể tìm thấy bất kỳ điều gì liên quan đến vấn đề này. Tôi cũng đã sử dụng tutorial này để thiết lập chính xác mọi thiết bị. Làm thế nào tôi có thể nhận được các phong cách hình ảnh để làm việc với một direct_upload để S3 ??
LOG
Processing by UpdatesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"fmxSfjg53jcouwmF/fdsoqxmDuq84=", "update"=>{"description"=>"", "direct_upload_url"=>"https://my-bucket.s3.amazonaws.com/uploads%2F1398310463606-c68nyl5gvgkqpvi-3708f19268a140853f118214d98924f8%2Fretro.png", "image_file_name"=>"retro.png", "image_file_size"=>"107715", "image_content_type"=>"image/png", "image_file_path"=>"/uploads%2F1398310463606-c68nyl5gvgkqpvi-3708f19268a140853f118214d98924f8%2Fretro.png"}, "commit"=>"Save changes"}
User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 29 ORDER BY "users"."id" ASC LIMIT 1
(0.3ms) BEGIN
Update Exists (0.5ms) SELECT 1 AS one FROM "updates" WHERE "updates"."id" = 730128 ORDER BY created_at DESC LIMIT 1
SQL (12.2ms) INSERT INTO "updates" ("created_at", "description", "direct_upload_url", "id", "image_content_type", "image_file_name", "image_file_path", "image_file_size", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING "id" [["created_at", Wed, 23 Apr 2014 22:34:29 CDT -05:00], ["description", ""], ["direct_upload_url", "https://my-bucket.s3.amazonaws.com/uploads%2F1398310463606-c68nyl5gvgkqpvi-3708f19268a140853f118214d98924f8%2Fretro.png"], ["id", 730128], ["image_content_type", "image/png"], ["image_file_name", "retro.png"], ["image_file_path", "/uploads%2F1398310463606-c68nyl5gvgkqpvi-3708f19268a140853f118214d98924f8%2Fretro.png"], ["image_file_size", 107715], ["updated_at", Wed, 23 Apr 2014 22:34:29 CDT -05:00], ["user_id", 29]]
Digest::Digest is deprecated; use Digest
[AWS S3 300 .5453 0 retries] copy_object(:bucket_name=>"my-bucket",:copy_source=>"my-bucket/uploads/1398310463606-c68nyl5gvgkqpvi-3708f19268a140853f118214d98924f8/retro.png",:key=>"updates/images/730128/original/retro.png",:metadata_directive=>"COPY",:storage_class=>"STANDARD")
Digest::Digest is deprecated; use Digest
[AWS S3 543 0.0493 0 retries] delete_object(:bucket_name=>"my-bucket",:key=>"uploads/1398310463606-c68nyl5gvgkqpvi-3708f19268a140853f118214d98924f8/retro.png")
Mẫu
class Update < ActiveRecord::Base
...
...
has_attached_file :image, :s3_protocol => :https,
:storage => :s3,
:styles => {
:profile => "550x330#" },
:convert_options => {
:thumb => "-quality 75 -strip" },
:s3_credentials => "#{Rails.root}/config/aws.yml",
:path => ":class/:attachment/:id/:style/:filename",
:url => ":s3_domain_url"
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
def self.copy_and_delete(paperclip_file_path, raw_source)
s3 = AWS::S3.new #create new s3 object
destination = s3.buckets['bucket-name'].objects[paperclip_file_path]
sub_source = CGI.unescape(raw_source)
sub_source.slice!(0) # the attached_file_file_path ends up adding an extra "/" in the beginning. We've removed this.
source = s3.buckets['bucket-name'].objects["#{sub_source}"]
source.copy_to(destination) #copy_to is a method originating from the aws-sdk gem.
source.delete #delete temp file.
end
khiển
def create
if(params[:url])
@update = Update.new
render "new" and return
end
if(params[:update][:image_file_path])
@update = current_user.updates.create(update_params)
respond_to do |format|
if @update.save
#we want a destination(paperclip_file_path) and a source(raw_source)
paperclip_file_path = "updates/images/#{@update.id}/original/#{params[:update][:image_file_name]}"
raw_source = params[:update][:image_file_path]
Update.copy_and_delete paperclip_file_path, raw_source #this is where we call a method to copy from temp location to where paperclip expects it to be.
format.html { redirect_to update_path(:id => @update.id), :flash => { :success => "<strong>Awesome!</strong> You've successfully created your update.".html_safe }}
format.json { render action: 'show', status: :created, location: @update }
else
format.html { render action: 'new' }
format.json { render json: @update.errors, status: :unprocessable_entity }
end
end
else
@update = Update.new
render action: "new", notice: "No file"
end
end
Vui lòng đặt một số thông tin nhật ký. Thật khó để tìm một giải pháp mà không có điều này. – lucianosousa
Bạn đang sử dụng phiên bản nào của đá quý 's3_direct_upload'? Lỗi này đã được sửa trong phiên bản 7.1.7 phát hành vào ngày 13 tháng 3. https://github.com/waynehoover/s3_direct_upload/pull/149 –
Agh. bạn có hy vọng của tôi lên. Tôi đang sử dụng 's3_direct_upload (0.1.7)' – tMTboss