简体   繁体   English

回形针S3 default_url

[英]Paperclip S3 default_url

I am using s3 with Paperclip which is working well. 我将s3与Paperclip一起使用时效果很好。 I am running into problems however with the default_url for missing attachements. 但是我遇到了default_url缺少附件的问题。 I want the default_url to be :attachement/default/:style in the same s3 bucket as the other files. 我希望default_url与其他文件在同一s3存储桶中为:attachement/default/:style However the default_url when used to generate a missing image is local for the rails app which is not what I want. 但是,当default_url用于生成丢失的图像时,它在Rails应用程序中是本地的,这不是我想要的。 Eg 例如

/avatar/default/thumb is not what I want for the default, instead I want {s3_base_url}/avatar/default/thumb . /avatar/default/thumb不是我想要的默认值,而是我想要{s3_base_url}/avatar/default/thumb I cannot figure out how to do this. 我不知道该怎么做。

So I solved it, but I am not overly pleased with the solution. 所以我解决了这个问题,但是我对解决方案并不太满意。

initializers/paperclip.rb Paperclip.interpolates(:s3_bucket) do |attachement, style| Rails.application.config.paperclip_defaults[:s3_credentials][:bucket] end initializers / Paperclip.interpolates(:s3_bucket) do |attachement, style| Rails.application.config.paperclip_defaults[:s3_credentials][:bucket] end Paperclip.interpolates(:s3_bucket) do |attachement, style| Rails.application.config.paperclip_defaults[:s3_credentials][:bucket] end

Model 模型

default_url: "http://:s3_bucket.s3.amazonaws.com/avatar/default/:style

It would of course be possible to add a fuller interpolation with the complete path to s3, but this is a workable solution. 当然可以在s3的完整路径上添加更完整的插值,但这是一个可行的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM