Class: M365ActiveStorage::BlobsController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- M365ActiveStorage::BlobsController
- Defined in:
- lib/m365_active_storage/controllers/blobs_controller.rb
Overview
SharePoint Blob Download Controller
Handles serving of attached files stored in SharePoint through a Rails action.
Responsibilities
-
Serve blobs securely using signed URLs
-
Validate blob access through ActiveStorage signatures
-
Handle Download requests with appropriate content headers
-
Recover from authentication errors (e.g., expired tokens)
-
Provide appropriate HTTP error responses
Route
This controller is automatically registered with Rails via the Railtie. Typically used with ActiveStorage’s url_for helper:
url_for(@document.file) # => /rails/active_storage/blobs/signed_id/document.pdf
Security
Access is secured through ActiveStorage signed IDs. The signature ensures:
-
Only authorized users can download blobs
-
URLs are time-limited if configured
-
Tampering with signed IDs is detected
Example Usage
In your Rails view:
<%= link_to "Download", @document.file, download: true %>
<%= image_tag @document.image %>
Error Handling
-
Invalid signatures return 404 Not Found
-
Authentication failures trigger token refresh and retry
-
Other errors return 500 Internal Server Error
Instance Method Summary collapse
-
#show ⇒ void
Display/download a blob.
Instance Method Details
#show ⇒ void
This method returns an undefined value.
Display/download a blob
Retrieves a blob by its signed ID and sends it to the client with appropriate Content-Type and disposition headers.
This action:
-
Extracts the signed blob ID from the URL
-
Validates the signature using ActiveStorage’s signing mechanism
-
Downloads the file from SharePoint
-
Returns it with appropriate HTTP headers
-
Handles token expiration by retrying once
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/m365_active_storage/controllers/blobs_controller.rb', line 71 def show # Skip sharepoint authentication - blob is secured via signed ID signed_id = params[:signed_id] blob = find_blob(signed_id) return head :not_found unless blob download(blob) rescue StandardError head :internal_server_error end |