Files
simple-aircraft-manager-rails/app/controllers/direct_uploads_controller.rb
T
rickyandClaude Opus 5.5 ef7cd2efba Admin setting for the maximum upload size
- Admin -> Settings: maximum upload size per file (1-1024 MB, default 50),
  stored in a new settings table and read on each use, so a change applies
  to every process at once
- Enforced by attachment validation and the direct-upload endpoint; upload
  forms, bulk upload and Admin -> About show the current limit
- .sam.zip import accepts files up to 1 GB to match

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 09:45:12 -05:00

26 lines
1007 B
Ruby

# Direct uploads (the browser sends each file straight to storage, then submits
# only its signed id). Active Storage's own endpoint lets anyone create blobs;
# this one requires a signed-in user and applies the upload rules up front.
class DirectUploadsController < ActiveStorage::DirectUploadsController
include Authentication
before_action :check_upload, only: :create
private
def blob_args
@blob_args ||= super.tap do |args|
args[:content_type] = Marcel::MimeType.for(name: args[:filename].to_s) if args[:content_type].blank?
end
end
def check_upload
error =
if !UploadValidation::ALLOWED_CONTENT_TYPES.include?(blob_args[:content_type])
"#{blob_args[:filename]} isn't an allowed file type"
elsif blob_args[:byte_size].to_i > UploadValidation.max_size
"#{blob_args[:filename]} is over the #{UploadValidation.max_size / 1.megabyte} MB upload limit"
end
render json: { error: error }, status: :unprocessable_entity if error
end
end