나는 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
도움을 주시면 감사하겠습니다. 감사!
버킷은 어느 지역에 있습니까? 나는 당신이 다른 지역 (코드가 사용하는 기본 지역은 us-east-1)을 통해 '연결'하려고하면 S3가 올바른 지역으로 리디렉션 할 것이라고 생각합니다. –
S3 문제에서 다운로드가 수정되었지만 다운로드가 손상되었습니다. 열 수 없습니다. 다음과 같은 오류가 나타납니다. "Adobe-PDF-Document-icon (1) .png"파일을 열 수 없습니다. t가 손상되었거나 미리보기에서 인식하지 못하는 파일 형식을 사용할 수 있습니다. – user2337569