神社-Cloudfront的派生端点和完整路径URL

我正在使用带有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_endpoint
plugin :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" }
redroom88 回答:神社-Cloudfront的派生端点和完整路径URL

  1. 由于后台作业将使用派生更新记录,所以最简单的方法是在客户端轮询记录的“显示”路线(即GET /images/:id)。在这种情况下,路由可以通过respond_to产生替代的JSON响应。

    或者,一旦处理完成,您可以通过WebSocket或类似message_bus之类的消息将消息从后台作业发送到客户端。

  2. 您可以为derivation_endpoint插件配置:host选项:

    Shrine.plugin :derivation_endpoint,host: "https://cloudfront.net"
    
本文链接:https://www.f2er.com/2827171.html

大家都在问