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(:style).size
gives a number not related to the actual file size
I didn't find either how to get the file size for a given style, other than the original one.
As seen in the paperclip source code, @user.attachment.size
returns the size of the file as originally assigned. There is no way to get it for a specific style...
A solution would be:
open(@user.attachment(:style)).size
But not efficient at all.
To do it well, you should probably add some "custom size" fields in your attachment table that you would fill once the attachment is saved for each style...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With