Skip to content

The difference between the file url and its actual location #2801

@rustsadb

Description

@rustsadb

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions