我正嘗試下載圖片並將其顯示在視圖欄中。如何從網址下載圖片並在視圖中顯示
我想下載它的原因是因爲url包含了一些我不太喜歡的api-keys。
迄今我已嘗試解決方案如下:
#Model.rb file
def getUrlMethod
someUrlToAPNGfile = "whatever.png"
file = Tempfile.new(['imageprependname', '.png'], :encoding => "ascii-8bit")
file.write(open(data).read)
return "#{Rails.application.config.action_mailer.default_url_options[:host]}#{file.path}"
end
#This seems to be downloading the image just fine. However the url that is returned does not point to a legal place
開發中我得到這個網址的圖片:localhost:3000/var/folders/18/94qgts592sq_yq45fnthpzxh0000gn/T/imageprependname20130827-97433-10esqxh.png
這圖片鏈接不指向任何地方有用。
我對什麼可能是錯誤的理論是:之前用戶可以請求它
- 的臨時文件被刪除不是一個合法的路線路線文件
我目前不知道有任何方法來解決這些問題。任何幫助?
順便說一句:我並不需要存儲的圖片我都顯示後,因爲它將從源頭上不斷變化的。
第一個鏈接真的幫我解決了。我有一些骨幹阻止了我做Brad Werth的方法。 – Automatico