我正在使用带有Shrine的Shrine将我的图像直接上传到S3,然后使用Cloudfront为它们提供服务。
我的设置运行良好,但是我一直试图回答2个问题:
1)用户通过Uppy上传新的图片。他们单击“创建图像页面”,这将创建一个新的“页面”对象。在使用Sidekiq在后台进程中创建Image派生类的同时,将用户带到空白页。成功创建派生并将其提升到/ store后,如何通过JS获得“弹出”图像?有没有可以回调的方法,还是有可能继续尝试通过JS找到派生类,直到它存在?
2)使用“派生端点”插件,所有图像URL都是相对的。有没有办法将其作为来自Cloudfront /自定义域的绝对URL?这是使用Rails的示例:
Ruby代码:
<%= image_tag(image.image_file.derivation_url(:banner,800,300)) %>
结果HTML:
<img src="/derivations/images/banner/800/300/...">
我该如何提供此结果网址:
<img src="http://abc123.cloudfront.net/derivations/images/banner/800/300/...">
这是否旨在防止DoS?谢谢。
将主机选项添加到“ derivation_endpoint”会导致以下错误以XML形式返回:
<Error>
<Code>accessDenied</Code>
<Message>access Denied</Message>
<RequestId>...</RequestId>
<HostId>...</HostId>
</Error>
这可以是我的Cloudfront访问设置吗?也许是CORS。
这是我在 image_uploader.rb
中设置的derivation_endpointplugin :derivation_endpoint,host: "http://abc123.cloudfront.net",prefix: "derivations",secret_key: ...,upload: true
routes.rb
mount Shrine.presign_endpoint(:cache) => "s3/params"
mount PhotoUploader.derivation_endpoint => "derivations/images"
config / initializers / Shrine.rb
Shrine.plugin :url_options,store: { host: "http://abc123.cloudfront.net" }