mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-05 11:24:42 +08:00
Improve file upload checks [SCI-4382]
This commit is contained in:
parent
a819e1b8f4
commit
11a5536af5
4 changed files with 21 additions and 2 deletions
|
@ -634,6 +634,12 @@
|
|||
}
|
||||
});
|
||||
newStepHandler();
|
||||
}).catch(() => {
|
||||
$('#new-step-assets-tab').addClass('has-error');
|
||||
$('#new-step-assets-group')
|
||||
.addClass('has-error')
|
||||
.prepend('<span class="help-block">' + I18n.t('general.file.upload_failure') + '</span>');
|
||||
animateSpinner(null, false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -467,7 +467,14 @@
|
|||
|
||||
upload.create((error, blob) => {
|
||||
if (error) {
|
||||
// Handle the error
|
||||
$.each($('.panel-result-attachment-new'), function() {
|
||||
if (!$(this).find('p').hasClass('dnd-total-error')) {
|
||||
$(this)
|
||||
.find('.panel-body')
|
||||
.append("<p class='dnd-total-error'>" + I18n.t('general.file.upload_failure') + '</p>');
|
||||
}
|
||||
});
|
||||
animateSpinner(null, false);
|
||||
} else {
|
||||
fd.append('results_names[' + index + ']', $('input[name="results[name][' + index + ']"]').val());
|
||||
fd.append('results_files[' + index + '][signed_blob_id]', blob.signed_id);
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
module ActiveStorage
|
||||
class DirectUploadsController < CustomBaseController
|
||||
before_action :check_file_size, only: :create
|
||||
|
||||
def create
|
||||
blob = ActiveStorage::Blob.create_before_direct_upload!(blob_args)
|
||||
render json: direct_upload_json(blob)
|
||||
|
@ -23,5 +25,9 @@ module ActiveStorage
|
|||
.merge(direct_upload: { url: blob.service_url_for_direct_upload,
|
||||
headers: blob.service_headers_for_direct_upload })
|
||||
end
|
||||
|
||||
def check_file_size
|
||||
render_403 if blob_args[:byte_size] > Rails.configuration.x.file_max_size_mb.megabytes
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2170,7 +2170,7 @@ en:
|
|||
size_exceeded: "File size must be less than %{file_size} MB."
|
||||
blank: "You didn't select any file"
|
||||
uploading: "If you leave this page, the file(s) that is/are currently uploading will not be saved! Are you sure you want to continue?"
|
||||
upload_failure: "Upload connection error. Try again or contact the administrator."
|
||||
upload_failure: "File upload error. Try again or contact the administrator."
|
||||
file_name_too_long: 'is too long (maximum is %{limit} characters, with extension)'
|
||||
text:
|
||||
not_blank: "can't be blank"
|
||||
|
|
Loading…
Add table
Reference in a new issue