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. I have to specify a redirect address in t开发者_运维技巧he form code. After the image is finished uploading, Amazon redirects the user to 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. A way where I can still get all that info and all the user sees is 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:
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.
精彩评论