이진 데이터를 사용자에게 공개하는 이미지에 대한 컨트롤러 작업을 만들 수 있습니다 .
map.connect ':user/:picture', :controller => 'accounts', :action => 'displayPic'
: 사용자가 로그인 한 경우에만) 접근이에 서문, 나는 장고/파이썬이 아닌 사람 루비/레일하지만, 내가 말할 수있는 구성은 다음과 같을 것입니다에서 왔어요
과 실제 컨트롤러는 다음과 같습니다.
class AccountsController < ApplicationController
def image
# check if user is logged in, then
user = Account.find(params[:user])
image = get_image(user, params[:picture])
send_data(image,
:filename => "#{params[:picture]}",
:type => "image/jpeg")
end
private
def get_image(image_name)
# do something to find image
# and return the binary data
# to the action
end
end
당신이 정말로 통해 이미지에 직접 액세스하지 뜻 이죠, 그러나
# images_controller.rb
ImagesController < ApplicationController
before_filter :require_user, :only => 'show'
def require_user
unless current_user
redirect_to root_url # or :back, or wherever
end
end
end
:
그래서 더 루비/레일 기술을 가진 사람이
: 레일 내에서 요청 개체를 확인할 수 있습니다. 랙 레이어 (http://guides.rubyonrails.org/rails_on_rack.html)에서 이미지 필터링을 높이거나 심지어 더 높은 이미지 필터링을 시도 할 수도 있습니다. – clyfe
@clyfe - 이것이 왜 성능 병목 현상이 될 수 있습니까? 레일스는 아파치가 처리하도록하는 대신 바이너리 데이터를 처리해야하기 때문에? –
예, Apache는 Ruby/Rails보다 빠릅니다. – Eric