简体   繁体   English

Ruby on Rails-清理网址参数

[英]Ruby on Rails - Clean up url parameters

I have a Rails app set up so that when a user uploads an image, it is sent directly to Amazon's S3. 我设置了一个Rails应用程序,以便在用户上传图像时将其直接发送到Amazon的S3。 I have to specify a redirect address in the form code. 我必须在表单代码中指定重定向地址。 After the image is finished uploading, Amazon redirects the user to www.redirect_address.com/?bucket=[BUCKET]&key=[KEY]&etag=[ETAG] 图片上传完成后,Amazon将用户重定向到www.redirect_address.com/?bucket=[BUCKET]&key=[KEY]&etag=[ETAG]

I need the bucket and key info to process the image, but is there a way for the user not to see all those parameters in the address box. 我需要bucketkey信息来处理图像,但是用户是否有办法不在地址框中看到所有这些参数。 A way where I can still get all that info and all the user sees is www.redirect_address.com www.redirect_address.com仍可让我获得所有信息并让用户看到的所有www.redirect_address.com

Thanks! 谢谢!

Tim 提姆

A good approach here is to use streaming by a front-end web server through x send file addons (see: nginx xsendfile or apache mod_xsendfile ), and in rails you'll have an action such as: 这里的一个好方法是通过x发送文件插件(参见: nginx xsendfileapache mod_xsendfile )由前端Web服务器使用流式传输,并且在rails中您可以执行以下操作:

def avatar
  if @user.avatar?
    response.headers["X-Accel-Redirect"] = @user.s3_avatar_url
    head :ok
  else
    head :error # or display a default image , whatever you want here
  end
end

And that sets an http header X-Accel-Redirect which gets sent to apache/nginx from your app server, which once you've got the module's linkd to above installed, whill tell the webserver to stream the file directly to the client, but the url for them stays the same as a normal request to your app (/users/:id/avatar or whatever) because there's no redirect. 并设置了一个HTTP标头X-Accel-Redirect ,该标头从您的应用服务器发送到apache / nginx,一旦您将模块链接到上述安装,便告诉网络服务器将文件直接流式传输到客户端,但是它们的网址与对您应用的正常请求(/ users /:id / avatar或其他)相同,因为没有重定向。

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

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