![](/img/trans.png)
[英]Carrierwave - Delete file from Amazon S3 but keep the record on db
[英]Refile + S3: delete attachment and keep db record
我正在使用refile
gem將文件上傳到S3
並具有以下模型
class DataFile < ActiveRecord::Base
attachment :document, destroy: true
end
數據庫中的相應表具有document_filename
和document_id
列以保存文件元數據。
我需要從S3
刪除文件,並將相應的行保留在數據庫中(我需要該行才能顯示該文件的名稱和刪除日期)。
我在努力
data_file.document = nil
data_file.save()
但這會刪除文件名。 是否有解決方案,可以從S3中刪除文件並保持document_filename
值。
我將在相應的模型中定義2個新列,並復制數據以在刪除后保留在那里。
這比保留格式錯誤的重新refile
對象更加一致:
data_file.update_attributes!(
file_name: data_file.document.filename,
removed_at: DateTime.now,
document: nil)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.