We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5214540 commit fdf259fCopy full SHA for fdf259f
1 file changed
lib/active_storage/service/db_service.rb
@@ -22,12 +22,17 @@ class Service::DBService < Service
22
23
def initialize(public: false, **)
24
@chunk_size = [ENV.fetch("ASDB_CHUNK_SIZE") { 1.megabytes }.to_i, MINIMUM_CHUNK_SIZE].max
25
+ @max_size = ENV.fetch("ASDB_MAX_FILE_SIZE", nil)&.to_i
26
@public = public
27
end
28
29
def upload(key, io, checksum: nil, **)
30
instrument :upload, key: key, checksum: checksum do
31
data = io.read
32
+ if @max_size && data.bytesize > @max_size
33
+ raise ArgumentError, "File size exceeds the maximum allowed size of #{@max_size} bytes"
34
+ end
35
+
36
if checksum
37
digest = Digest::MD5.base64digest(data)
38
raise ActiveStorage::IntegrityError unless digest == checksum
0 commit comments