How to upload with custom metadata and proper Pretty Location?

I am new to shrine from carrierwave (only using shrine on new models)
And we have this file upload code:

scca = ::Spacious::Chat::Channel::Attachment::Record.new(
  spacious_chat_channel_record_id: ::Spacious::Chat::Channel::Record.last.id,
)
io = StringIO.new
io.puts(::File.read(Rails.root.join("spec/support/files/square.jpg")))
io.rewind
attacher = scca.file_attacher
uploaded_file = attacher.attach(
  io,
  metadata: {
    filename: "image.jpg",
    mime_type: "image/jpg",
  },
)
# uploaded_file.url
# => "https://cdn.spacious.hk/uploads/spacious_chat_channel_attachment_record/file/4b7756b4e890240ea02267053dc5400f.jpeg"
scca.save!
# uploaded_file.url
# => "https://cdn.spacious.hk/uploads/spacious_chat_channel_attachment_record/25/file/4b7756b4e890240ea02267053dc5400f.jpeg"

However I want the file at https://cdn.spacious.hk/uploads/spacious_chat_channel_attachment_record/file/4b7756b4e890240ea02267053dc5400f.jpeg to be another URL like
https://cdn.spacious.hk/uploads/cache/spacious_chat_channel_attachment_record/file/4b7756b4e890240ea02267053dc5400f.jpeg
So that I can use S3 life cycle rule to delete them

Can anyone give some advice?

And I realize I used wrong method
Silly me

scca = ::Spacious::Chat::Channel::Attachment::Record.new(
  spacious_chat_channel_record_id: ::Spacious::Chat::Channel::Record.last.id,
)
io = StringIO.new
io.puts(::File.read(Rails.root.join("spec/support/files/square.jpg")))
io.rewind
attacher = scca.file_attacher
uploaded_file = attacher.assign(
  io,
  metadata: {
    filename: "image.jpg",
    mime_type: "image/jpg",
  },
)
scca.save!

Correct, Attacher#attach uploads straight to permanent storage.

Note that you can simplify your code by passing the open file directly:

# ...
io = Rails.root.join("spec/support/files/square.jpg").open("rb")
# ...

Thanks
But the code here is just a test case
We actually receive file from params in controller