2014-04-30 5 views
0

링크를 클릭하면 아마존 파일이 잘 다운로드됩니다. 아마존에는 수천 개의 PDF 파일이 있습니다. 지금 mongoid id 그 아마존 파일의 이름. 파일을 다운로드 할 때 해당 ID로 저장합니다. 하지만 그 파일을 로컬에 저장하기 전에 파일의 이름을 바꾸고 싶습니다. 내 mongoid에 이름 필드가 있습니다. 이름 바꾸기 및 다운로드 아마존 파일 ruby ​​mongoid

include Mongoid::Paperclip 

has_mongoid_attached_file :profile_doc 

은 내가 파일 다운로드 할 때 파일의 이름을 변경하는 방법

def download 
    if @company.send(doc).exists? 
    redirect_to @company.send(doc).expiring_url 
    else 
    respond_with_error(:not_found) 
    end 
end 

을 호출 할이 컨트롤러 액션 같은를 연결할 때. 지금 파일이 다운로드 중입니다. 50sfdkkmzd.pdfname.pdf을 저장하고 싶습니다.

감사합니다.

+0

http://stackoverflow.com/questions/10280822/paperclip-rename-file-before-saving –

답변

1

는 잘

def download 
    if @company.send(doc).exists? 
    data = open(@company.send(doc).expiring_url) 
    send_data data.read, :filename => "name.pdf", :type => data.content_type 
    else 
    respond_with_error(:not_found) 
    end 
end 
+0

감사를 작동해야합니다,이 시도. 큰. 그것은 잘 작동합니다. – Selvamani

+0

그리고 왜 내가'send_file'을 사용해서는 안되는지 알고 싶습니다. – Selvamani

+0

당신은 그것을 사용할 수 있습니다 ... 나는 send_file을 많이 사용하지 않았습니다 ... – abhas