2013-04-30 5 views
0

나는 tutorial과 함께 다음을 수행하고 클립 및 S3를 사용하여 레일 파일 공유 응용 프로그램을 작성합니다. S3에 파일 업로드가 완벽하게 작동하지만 난 업로드 된 파일 이름을 클릭했을 때이 오류가 얻을 :레일 및 Amazon S3

자산 :

여기
app/controllers/assets_controller.rb:15:in `get' 

OpenURI::HTTPError in AssetsController#get 

301 Moved Permanently (Invalid Location URI) 

그것은 나를 가리키는 것은 내 코드입니다 .controller.rb

def get 
    asset = current_user.assets.find_by_id(params[:id]) 

    if asset 
    #Parse the URL for special characters first before downloading 
    data = open(URI.parse(URI.encode(asset.uploaded_file.url))) 

    #then again, use the "send_data" method to send the above binary "data" as file. 
    send_data data, :filename => asset.uploaded_file_file_name 

    #redirect to amazon S3 url which will let the user download the file automatically 
    #redirect_to asset.uploaded_file.url, :type => asset.uploaded_file_content_type 
    else 
    flash[:error] = "Don't be cheeky! Mind your own assets!" 
    redirect_to root_url 
    end 
end 

assets.controller.rb

attr_accessible :user_id, :uploaded_file 

    belongs_to :user 

    #set up "uploaded_file" field as attached_file (using Paperclip) 
    has_attached_file :uploaded_file, 
       :path => "assets/:id/:basename.:extension", 
       :storage => :s3, 
       :s3_credentials => ::Rails.root.join('config/amazon_s3.yml'), 
       :bucket => "Sharebox" 


validates_attachment_size :uploaded_file, :less_than => 10.megabytes  
validates_attachment_presence :uploaded_file 

def file_name 
    uploaded_file_file_name 

end 

end 

도움을 주시면 감사하겠습니다. 감사!

+0

버킷은 어느 지역에 있습니까? 나는 당신이 다른 지역 (코드가 사용하는 기본 지역은 us-east-1)을 통해 '연결'하려고하면 S3가 올바른 지역으로 리디렉션 할 것이라고 생각합니다. –

+0

S3 문제에서 다운로드가 수정되었지만 다운로드가 손상되었습니다. 열 수 없습니다. 다음과 같은 오류가 나타납니다. "Adobe-PDF-Document-icon (1) .png"파일을 열 수 없습니다. t가 손상되었거나 미리보기에서 인식하지 못하는 파일 형식을 사용할 수 있습니다. – user2337569

답변

0

업로드 후 몇 분 후에 다시 시도해도 동일한 문제가 발생합니까?

파일에 액세스 할 수있을 때까지 S3 시간이 걸릴 수 있습니다.

+0

도움을 주셔서 감사합니다. 버킷 영역이 일치하지 않는 것이 었습니다. S3에서 다운로드 할 수는 있지만 파일을 열 때 오류가 발생합니다. "Adobe-PDF-Document-icon (1) .png"파일을 열 수 없습니다. t가 손상되었거나 미리보기에서 인식하지 못하는 파일 형식을 사용할 수 있습니다. – user2337569

+0

OS X 미리보기에서 .png 형식을 인식해야합니다. – Tilo