How do I fetch the file size of each style of a paperclip attachment?
@user.attachment_file_size
doesn\'t seem to work
@user.attachment(
It seems it is possible actually
Just have to cath the temporary files for each style and applying size method.
let's say you have two styles large
and small
for your attachment called image
and you have created two extra fields in your model large_size
and small_size
to save those values.
Just add the below bit of code to your model:
before_create :assign_sizes
private
def assign_sizes
self.large_size = image.queued_for_write[:large].size.to_i
self.small_size = image.queued_for_write[:small].size.to_i
end
The fields large_size
and small_size
will be popuated with each style file size. And this will be done before the files are sent to S3 for example. So there is no extra querying the files headers from S3.