title: ActiveStorage - get image dimensions after upload
body: <p>I am using Rails + ActiveStorage to upload image files, and would like to save the width and height in the database after upload. However, I'm having trouble finding any examples of this anywhere.</p>
  
  <p>This is what I've cobbled together from various API docs, but just end up with this error: <code>private method 'open' called for #&lt;String:0x00007f9480610118&gt;</code>. Replacing <code>blob</code> with <code>image.file</code> causes rails to log "Skipping image analysis because ImageMagick doesn't support the file" (<a href="https://github.com/rails/rails/blob/master/activestorage/lib/active_storage/analyzer/image_analyzer.rb#L39" rel="noreferrer">https://github.com/rails/rails/blob/master/activestorage/lib/active_storage/analyzer/image_analyzer.rb#L39</a>).</p>
  
  <p>Code:</p>
  
  <pre><code>class Image &lt; ApplicationRecord
    after_commit { |image| set_dimensions image }
  
    has_one_attached :file
  
    def set_dimensions(image)
      if (image.file.attached?)
        blob = image.file.download
  
        # error: private method `open' called for #&lt;String:0x00007f9480610118&gt;
        meta = ActiveStorage::Analyzer::ImageAnalyzer.new(blob).metadata
      end
    end
  end
  </code></pre>
  
  <p>This approach is also problematic because <code>after_commit</code> is also called on destroy.</p>
  
  <p><strong>TLDR:</strong> Is there a "proper" way of getting image metadata immediately after upload?</p>