Skip to content
  • Alex Ghiculescu's avatar
    27bee74d
    Active Storage: `Blob` creation shouldn't crash if no service selected · 27bee74d
    Alex Ghiculescu authored
    https://github.com/rails/rails/issues/41653 noted an issue where if there's service configured (`config.active_storage.service` is commented out), Blob creation via direct upload crashes:
    
    ```
    Started POST "/rails/active_storage/direct_uploads" for ::1 at 2021-03-09 13:02:57 -0800
    Processing by ActiveStorage::DirectUploadsController#create as JSON
      Parameters: {"blob"=>{"filename"=>"banana.jpg", "content_type"=>"image/jpeg", "byte_size"=>577085, "checksum"=>"W/vo/JqBNmJHMCaL+PRlBQ=="}, "direct_upload"=>{"blob"=>{"filename"=>"banana.jpg", "content_type"=>"image/jpeg", "byte_size"=>577085, "checksum"=>"W/vo/JqBNmJHMCaL+PRlBQ=="}}}
    Completed 500 Internal Server Error in 12ms (ActiveRecord: 3.3ms | Allocations: 5864)
    
    NoMethodError (undefined method `name' for nil:NilClass):
    
    activestorage (6.1.3) app/models/active_storage/blob.rb:52:in `block in <class:Blob>'
    activesupport (6.1.3) lib/active_support/callbacks.rb:427:in `instance_exec'
    ```
    
    This PR fixes that crash. Blob creation will still fail, but with a more informative error about a `service_name` being required.
    27bee74d
    Active Storage: `Blob` creation shouldn't crash if no service selected
    Alex Ghiculescu authored
    https://github.com/rails/rails/issues/41653 noted an issue where if there's service configured (`config.active_storage.service` is commented out), Blob creation via direct upload crashes:
    
    ```
    Started POST "/rails/active_storage/direct_uploads" for ::1 at 2021-03-09 13:02:57 -0800
    Processing by ActiveStorage::DirectUploadsController#create as JSON
      Parameters: {"blob"=>{"filename"=>"banana.jpg", "content_type"=>"image/jpeg", "byte_size"=>577085, "checksum"=>"W/vo/JqBNmJHMCaL+PRlBQ=="}, "direct_upload"=>{"blob"=>{"filename"=>"banana.jpg", "content_type"=>"image/jpeg", "byte_size"=>577085, "checksum"=>"W/vo/JqBNmJHMCaL+PRlBQ=="}}}
    Completed 500 Internal Server Error in 12ms (ActiveRecord: 3.3ms | Allocations: 5864)
    
    NoMethodError (undefined method `name' for nil:NilClass):
    
    activestorage (6.1.3) app/models/active_storage/blob.rb:52:in `block in <class:Blob>'
    activesupport (6.1.3) lib/active_support/callbacks.rb:427:in `instance_exec'
    ```
    
    This PR fixes that crash. Blob creation will still fail, but with a more informative error about a `service_name` being required.
Loading