-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Description
Some files have a different url and the actual file name in the storage. My uploader:
class AttachmentUploader < CarrierWave::Uploader::Base
def store_dir
"uploads/#{model.attachable.class.to_s.underscore.split('/').last}_files"
end
def size_range
0..15.megabytes
end
def extension_allowlist
%w(jpg jpeg gif png txt xlsx xls pdf csv doc docx rtf zip rar 7z gz tar.gz pptx ppt pages numbers)
end
def filename
return unless original_filename
array_name = original_filename.split('.')
file_extension = array_name.last
body_name = array_name.excluding(file_extension)
"#{body_name.join('.')}_#{Time.current.strftime('%d.%m.%Y-%H:%M:%S')}.#{file_extension}"
end
end
Example of problem:
image_13.11.2025-10:29:32.jpg # attachment identifier (attachment.file.identifier)
/uploads/pass_person_files/image_13.11.2025-10%3A29%3A32.jpg # attachment url (attachment.file.url)
But file url shows the wrong location. In fact, the image is located at:
/uploads/pass_person_files/image_13.11.2025-10%3A29%3A33.jpg # file in the storage
I noticed a pattern that for broken records in the database, the created_at field has a value of ~0.99 milliseconds.
Thu, 13 Nov 2025 10:29:32.994930000 UTC +00:00
To upload files, I usually use Attachment.create!(...file:)
Maybe someone has encountered such a problem?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels