Skip to content

Commit 655ed5d

Browse files
committed
Avoids uploading to S3 files bigger than max size
1 parent 2b19fd3 commit 655ed5d

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

app/assets/javascripts/s3-upnow.js.coffee

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ $(document).on 'change', (e) ->
33
if (input.prop('tagName') == "INPUT" && input.prop('type') == "file" && input.data('upnow'))
44
return if (!input.prop('files'))
55
file = input.prop('files')[0]
6+
max_file_size = Number(input.attr('max_file_size') || <%= 500.megabytes %>)
7+
if Number(file.size) > max_file_size
8+
alert("<%= I18n.t('s3_upnow.max_file_size') %>: #{max_file_size/1024/1024}mb")
9+
return
610
file.unique_id = Math.random().toString(36).substr(2,16)
711

812
dispatchEvent = (name, detail) ->

config/locales/en.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
en:
2+
s3_upnow:
3+
max_file_size: 'File size greater than the max permitted'

0 commit comments

Comments
 (0)