日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

将文件名发送到服务器,将Paperclip路径文件名从服务器更新到s3(Updating Paperclip path file names from on server to s3)...

發布時間:2025/3/21 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 将文件名发送到服务器,将Paperclip路径文件名从服务器更新到s3(Updating Paperclip path file names from on server to s3)... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

將Paperclip路徑文件名從服務器更新到s3(Updating Paperclip path file names from on server to s3)

我有一個回形針實例,我將我的文件遷移到另一個區域。 最初文件存儲在我的服務器上,只根據創建的記錄的id和原始id給出了文件名。 現在我將它們移動到s3并希望更新文件名以使其正常工作。 我設置了我的回形針配置,如下所示:

:path => ":class/:attachment/:hash-:style.:extension",

:url => ":s3_domain_url",

:hash_secret => SECRET,

:hash_data => ":class/:attachment/:id/:updated_at"

我更新了我的文件的原始記錄文件名是唯一的,并將它們移動到我的s3實例。 不幸的是現在我無法從s3下載文件,我認為這是因為paperclip使用了錯誤的文件名路徑。 一個基于路徑默認值的,現在使用我的配置文件設置。 我希望能夠更新我的文件file_name字段,以便新文件的路徑正確,我可以適當地下載它們。 有沒有辦法直接根據我的秘密和hash_data調用回形針散列函數,這樣我就可以更新那些file_name字段并能夠立即提取這些記錄? 自從我的原始服務器移動后上傳的所有內容似乎都正常工作。

I have a paperclip instance that I am migrating my files to a different area. Originally the files were stored on my server and just given a filename based on the id of the record created and the original id. Now I'm moving them to s3 and want to update the filenames to work appropriately. I setup my paperclip config like so:

:path => ":class/:attachment/:hash-:style.:extension",

:url => ":s3_domain_url",

:hash_secret => SECRET,

:hash_data => ":class/:attachment/:id/:updated_at"

I updated the original records filenames for my files to be unique and moved them over to my s3 instance. Unfortunately now I am unable to pull down the files from s3 and I think it is because paperclip is using the wrong path for the filenames. One that is based off the path default that is now set using my config file. I want to be able to update my files file_name field so that the path is correct for the new files and I am able to download them appropriately. Is there a way to call paperclips hashing function based on my secret and hash_data directly so I can update those file_name fields and be able to pull those records now? Everything that has been uploaded since the move from my original servers seems to work appropriately.

原文:https://stackoverflow.com/questions/31347373

更新時間:2021-01-16 09:01

最滿意答案

假設您有一個名為profile_pic的附件的模型用戶 ;

進入rails控制臺,例如。 rails c然后獲取你有附件的模型的對象,例如。 u = User.find(100) 。

現在輸入u.profile_pic.url以獲取url或u.profile_pic_file_name以獲取文件名。

要查看其他選項(例如舊選項)的效果,您可以執行此操作;

p = u.profile_pic # gets the paperclip attachment for profile_pic

puts p.url # gets the current url

p.options.merge!(url: '/blah/:class/:attachment/:id_partition/:style/:filename')

puts p.url # now shows url with the new options

類似地, p.path將顯示本地文件路徑,其中包含您選擇的任何選項。

長話短說,有點像;

User.where('created_at < some_date').map do |x|

"#{x.id} #{x.profile_pic_file_name} #{x.profile_pic.path}"

end

應該給你你想要的:)

Say you have a model User with an attachment named profile_pic;

Go into the rails console eg. rails c and then get an object for the model you have the attachment on, eg. u = User.find(100).

Now type u.profile_pic.url to get the url or u.profile_pic_file_name to get the filename.

To see the effect of other options (for example your old options) you can do;

p = u.profile_pic # gets the paperclip attachment for profile_pic

puts p.url # gets the current url

p.options.merge!(url: '/blah/:class/:attachment/:id_partition/:style/:filename')

puts p.url # now shows url with the new options

Similarly p.path will show the local file path with whatever options you pick.

Long story short, something like;

User.where('created_at < some_date').map do |x|

"#{x.id} #{x.profile_pic_file_name} #{x.profile_pic.path}"

end

should give you what you want :)

相關問答

假設你在用戶的實例上有一個名為頭像的附件,你可以使用user.avatar.path來獲得文件系統上文件的完整路徑,并且你可以使用user.avatar.url來給出你可能的路徑用于圖像標簽和什么。 那是你的意思嗎? Assuming you had an attachment called avatar on an instance of a user, you can use user.avatar.path to get the full path of the file on the fi

...

假設您有一個名為profile_pic的附件的模型用戶 ; 進入rails控制臺,例如。 rails c然后獲取你有附件的模型的對象,例如。 u = User.find(100) 。 現在輸入u.profile_pic.url以獲取url或u.profile_pic_file_name以獲取文件名。 要查看其他選項(例如舊選項)的效果,您可以執行此操作; p = u.profile_pic # gets the paperclip attachment for profile_pic

puts p

...

你沒有設置一個桶。 它位于你的s3.yml文件中,但是你沒有從你對has_attached_file的調用中讀取這個值。 Paperclip S3 docs: http : //rubydoc.info/gems/paperclip/Paperclip/Storage/S3#s3_protocol-instance_method 另外,請注意那些告訴你不要使用Heroku的s3.yml文件的人。 這是一種浪費,只是添加了抽象,無需購買任何東西。 您已經使用所需的值設置了ENV,因此請使用它們。 我

...

我有同樣的問題。 我認為這與Paperclip v3代碼有關。 我在我的Gemfile中指定使用舊版本。 # Gemfile

gem "paperclip", "~> 2.7.0"

和裁剪工作。 我不確定這對你來說是否是一個很好的解決方案,但它暫時對我有用。 I have the same issue. I think it's related to the Paperclip v3 code. I specified in my Gemfile to use the older versio

...

無論如何,任何可以使用開發工具的人都可以看到S3 URL,因此暴露它不是一個安全漏洞。 有些人認為這是糟糕的用戶體驗,但這是另一次的討論。 The S3 URL will be visible to anyone who can use dev tools anyway so exposing it is not a security vulnerability. Some would argue it is bad UX but that is a discussion for another

...

以前有這個問題! 通過將桶變量放入模型本身(實時代碼)來解決它: #app/models/image.rb

has_attached_file :image,

:styles => { :medium => "x300", :thumb => "x100" },

:default_url => "**********",

:storage => :s3,

:bucke

...

我不完全確定這是它,但是你加載的s3_credentials與我在生產網站上使用的不同。 我的配置行是: :s3_credentials => "#{RAILS_ROOT}/config/s3.yml"

代替 :s3_credentials => YAML.load_file("#{RAILS_ROOT}/config/s3.yml")[RAILS_ENV]

I'm not entirely sure this is it, but your loading of the s3_credent

...

據我所知,我確實需要將S3對象轉換為File ,如@ oregontrail256所示。 我使用Fog gem來做到這一點。 s3 = Fog::Storage.new(

:provider => 'AWS',

:aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],

:aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']

)

directory

...

哦耶!! 最后我抓住了它:我需要更改我的_form.html.erb

...

至 { :multipart => true } do |f| %>

...

Oh yeah!! Finally i caught it: I need to change my _form.html.erb, from

...

我通過使用后保存解決了這個問題。 請在此處查看與此主題相關的答案 I have worked around this, by using the after save. See my answer related to this subject here

總結

以上是生活随笔為你收集整理的将文件名发送到服务器,将Paperclip路径文件名从服务器更新到s3(Updating Paperclip path file names from on server to s3)...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲午夜视频 | 伊人久久免费视频 | 婷婷俺也去 | 少妇伦子伦精品无吗 | 色在线影院 | 国模私拍xvideos私拍 | 天天撸在线视频 | 成人拍拍视频 | 国产一区二区伦理 | 爱操综合 | 日韩亚洲国产欧美 | 精品九九| 香蕉视频97 | 天堂av√| 老师的肉丝玉足夹茎 | 免费日韩在线 | 蜜桃av鲁一鲁一鲁一鲁俄罗斯的 | 免费观看高清在线 | 国产精品久久久久久久一区探花 | 亚洲女优视频 | 少妇户外露出[11p] | 手机福利视频 | 无码人妻一区二区三区在线视频 | 成人永久免费视频 | 狠狠爱夜夜 | 欧美激情一区二区三级高清视频 | 国产精品11| 国产精品麻豆一区二区 | 成人黄色电影网址 | 黄色成年视频 | 白丝久久 | 美足av | 欧美碰碰碰| 91精品国产乱码在线观看 | 蜜桃臀av一区二区三区 | 黄色一级一片 | 国产区在线观看 | 亚洲熟女少妇一区二区 | av视觉盛宴| 在线观看国产福利 | 嫩草影院懂你的 | 国产精品久久久久久久免费观看 | 亚洲精品视频中文字幕 | 中文字幕第一页在线视频 | 欧美激情精品久久久久久 | 美女扒开屁股让男人桶 | 欧美另类69 | 欧美日韩中字 | 激情瑟瑟 | 免费v片在线观看 | 9999av| 男人资源站 | 性欧美大战久久久久久久免费观看 | 天天摸天天舔天天操 | 日韩精品一区二区亚洲av性色 | 久久综合激的五月天 | 亚洲一区二区三区在线观看视频 | 法国空姐电影在线 | 91在线公开视频 | 国产四区视频 | 久久综合久久88 | av中文字幕在线免费观看 | 日韩mv欧美mv国产网站 | 草莓巧克力香氛动漫的观看方法 | 欧美性猛交xxxx乱大交3 | 欧美视频一 | 蜜桃视频在线入口www | 欧美日韩人妻精品一区 | wwwxxx国产| 警察高h荡肉呻吟男男 | 欧美成人乱码一区二区三区 | 国产又粗又猛又爽又黄的视频一 | 免费黄色看片 | 亚洲第一视频 | 中日韩欧美在线观看 | 国产午夜大地久久 | 免费看91 | www.天堂在线 | 欧美抠逼视频 | 日本精品一二区 | 日本va在线观看 | 亚洲第一狼人区 | 中文字幕一区二区三区手机版 | 日本www在线播放 | 午夜一区二区三区 | 久久经典视频 | 中文字幕一区二区不卡 | 色综合久| 亚洲aⅴ乱码精品成人区 | 国精产品99永久一区一区 | 日韩小视频在线观看 | www黄色av | 中文精品久久久久人妻不卡 | 午夜影院福利社 | 国产大片一区二区三区 | 骚虎视频在线观看 | 欧美一a一片一级一片 | 日韩精品一区二区三区久久 | 香蕉视频一区二区三区 |