send_file으로 파일을 다운로드하는 방법?
-
20-12-2019 - |
문제
누군가가 나에게 계몽 할 수 있습니까?
send_file
내부에 Per image.jpg
파일이 있습니다.내 컨트롤러 에서이 작업을 시도했습니다.
def download
send_file ("#{Rails.root}/public/images/image.jpg")
end
def download
send_file ("#{Rails.root}/assets/images/image.jpg")
end
def download
send_file ("#{Rails.root}/images/image.jpg")
end
def download
send_file ("/public/images/image.jpg")
end
def download
send_file ("/assets/public/images/image.jpg")
end
def download
send_file ("/assets/images/image.jpg")
end
.
라는 각 경로에 대해
ActionController::MissingFile in HomeController#download
Cannot read file 'some_path'
.
여기서 문제가 될 수 있습니까?감사합니다!
해결책
시도 :
IMAGES_PATH = File.join(Rails.root, "public", "images")
def download
send_file(File.join(IMAGES_PATH, "image.jpg"))
end
. 다른 팁
In your view =>
<%= link_to "click here to download", signed_feeds_pdf_path(:feed_image_path => feed_image.feedimage.path), target: '_self' %>
In your controller =>
def pdf
file_name = params[:feed_image_path].split('/').last
@filename ="#{Rails.root}/public/uploads/feed_image/feedimage/#{file_name}"
send_file(@filename ,
:type => 'application/pdf/docx/html/htm/doc',
:disposition => 'attachment')
end
soo simple......
. 파일을 공용 폴더로 이동하는 것이 좋습니다.어쨌든, 이렇게하십시오
send_file(Rails.root.join('app' , 'assets', 'images', 'image.jpg'))
. 우리는 그것이 캐시되도록 광산 유형을 지정해야합니다.
send_file ("#{Rails.root}/public"+image.image_path), :type => "image/jpeg", :disposition => 'inline'
. 여전히 답변을 찾고있는 모든 사용자는 Ajax 호출에 응답 할 때 send_data 및 send_file이 작동하지 않습니다.대신 폼을 제출하거나 <a href=..>
를 사용하여 컨트롤러 메소드를 호출하고 파일을 다운로드하십시오.
제휴하지 않습니다 StackOverflow