通过应用程序代理文件。这避免了重定向,并使文件更容易缓存。
警告:默认情况下,所有 Active Storage 控制器都是公共可访问的。生成的 URL 难以猜测,但按设计是永久的。如果您的文件需要更高水平的保护,请考虑实现 身份验证控制器。
方法
- S
包含的模块
实例公共方法
show() 链接
源文件: show | 在 GitHub 上
# File activestorage/app/controllers/active_storage/blobs/proxy_controller.rb, line 14 def show if request.headers["Range"].present? send_blob_byte_range_data @blob, request.headers["Range"] else http_cache_forever public: true do response.headers["Accept-Ranges"] = "bytes" response.headers["Content-Length"] = @blob.byte_size.to_s send_blob_stream @blob, disposition: params[:disposition] end end end