如何顯示存儲在S3亞馬遜在rails應用程序中的pdf文件?RAILS S3顯示存儲在亞馬遜S3的pdf文件
0
A
回答
0
上傳文件到S3時文件名必須有沒有空格或特殊字符。
要與空間使用以下
yourmodel.rb
class Video < ActiveRecord::Base
has_attached_file :video,
:path => ":rails_root/public/system/:attachment/:id/:style/:normalized_video_file_name",
:url => "/system/:attachment/:id/:style/:normalized_video_file_name"
Paperclip.interpolates :normalized_video_file_name do |attachment, style|
attachment.instance.normalized_video_file_name
end
def normalized_video_file_name
"#{self.id}-#{self.video_file_name.gsub(/[^a-zA-Z0-9_\.]/, '_')}"
end
end
什麼是我們在這裏做上傳文件?很簡單,在has_attached_file中,我們編輯paperclip默認返回路徑和url的方式,這是保存和加載文件以顯示它時最相關的組件。回形針默認值是:前面有
path default => ":rails_root/public/system/:attachment/:id/:style/:filename"
url default => "/system/:attachment/:id/:style/:filename"
價值觀 ':' 是標準的插值回形針有
http://blog.wyeworks.com/2009/7/13/paperclip-file-rename
0
你需要一個補充:s3_headers進入您的has_attachment行:
has_attached_file :asset,
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => "uploads/:id/:basename.:extension",
:s3_headers => {"Content-Disposition" => "attachment"},
:s3_permissions => 'authenticated-read',
:s3_protocol => "http",
:bucket => "my_bucket_or_something"
相關問題
- 1. 亞馬遜S3蝦PDF
- 2. Rails和亞馬遜S3
- 3. 亞馬遜S3 - 存儲桶策略
- 4. php亞馬遜s3存儲桶創建
- 5. Android亞馬遜s3存儲桶
- 6. 亞馬遜S3說法鬥不存在
- 7. lighttpd在亞馬遜s3
- 8. 解壓亞馬遜S3中的文件
- 9. 亞馬遜S3中的重複文件
- 10. 更新亞馬遜S3存儲桶中的文件
- 11. 將本地存儲的文件移動到亞馬遜S3
- 12. Carrierwave - 配置亞馬遜S3
- 13. Android的亞馬遜S3 TransferUtility
- 14. ios上傳文件到亞馬遜s3
- 15. 亞馬遜S3和MP4文件
- 16. 亞馬遜S3文件上傳
- 17. 亞馬遜s3文件從android下載
- 18. 亞馬遜S3丟失文件
- 19. 亞馬遜S3文件上傳
- 20. 上傳文件到亞馬遜s3
- 21. 亞馬遜S3查看文件
- 22. 使用Laravel文件系統選擇亞馬遜S3存儲類
- 23. 移動幼蟲存儲文件夾到亞馬遜s3
- 24. 發送mysql轉儲到亞馬遜S3
- 25. 在文件系統中,亞馬遜S3數據存儲的存儲圖像
- 26. 從亞馬遜S3刪除
- 27. 亞馬遜s3桶ListObject
- 28. android亞馬遜s3上傳
- 29. zcat上亞馬遜s3
- 30. 離線亞馬遜S3