Bug 32030: Max document file size - server-side validation
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
7423641322
commit
2c147d5cdd
|
|
@ -48,7 +48,7 @@ sub replace_with {
|
|||
$schema->txn_do(
|
||||
sub {
|
||||
my $existing_documents = $obj->documents;
|
||||
|
||||
my $max_allowed_packet = C4::Context->dbh->selectrow_array(q{SELECT @@max_allowed_packet});
|
||||
# FIXME Here we are not deleting all the documents before recreating them, like we do for other related resources.
|
||||
# As we do not want the content of the documents to transit over the network we need to use the document_id (and allow it in the API spec)
|
||||
# to distinguish from each other
|
||||
|
|
@ -69,6 +69,9 @@ sub replace_with {
|
|||
for my $document (@$documents) {
|
||||
my $file_content = defined($document->{file_content}) ? decode_base64( $document->{file_content} ) : "";
|
||||
my $mt = MIME::Types->new();
|
||||
# Throw exception if uploaded file exceeds server limit
|
||||
Koha::Exceptions::PayloadTooLarge->throw("File size exceeds limit defined by server") if length($file_content) > $max_allowed_packet;
|
||||
|
||||
if ( $document->{document_id} ) {
|
||||
# The document already exists in DB
|
||||
$existing_documents->find( $document->{document_id} )
|
||||
|
|
|
|||
|
|
@ -24,6 +24,10 @@ use Exception::Class (
|
|||
isa => 'Koha::Exception',
|
||||
description => 'The required object doesn\'t exist',
|
||||
},
|
||||
'Koha::Exceptions::PayloadTooLarge' => {
|
||||
isa => 'Koha::Exception',
|
||||
description => 'Request entity is larger than limits defined by server',
|
||||
},
|
||||
'Koha::Exceptions::ObjectNotCreated' => {
|
||||
isa => 'Koha::Exception',
|
||||
description => 'The object have not been created',
|
||||
|
|
|
|||
|
|
@ -148,6 +148,12 @@ sub add {
|
|||
}
|
||||
);
|
||||
}
|
||||
elsif ( $_->isa('Koha::Exceptions::PayloadTooLarge') ) {
|
||||
return $c->render(
|
||||
status => 413,
|
||||
openapi => { error => $_->error }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$c->unhandled_exception($_);
|
||||
|
|
@ -224,6 +230,12 @@ sub update {
|
|||
}
|
||||
);
|
||||
}
|
||||
elsif ( $_->isa('Koha::Exceptions::PayloadTooLarge') ) {
|
||||
return $c->render(
|
||||
status => 413,
|
||||
openapi => { error => $_->error }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$c->unhandled_exception($_);
|
||||
|
|
|
|||
|
|
@ -135,6 +135,12 @@ sub add {
|
|||
}
|
||||
);
|
||||
}
|
||||
elsif ( $_->isa('Koha::Exceptions::PayloadTooLarge') ) {
|
||||
return $c->render(
|
||||
status => 413,
|
||||
openapi => { error => $_->error }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$c->unhandled_exception($_);
|
||||
|
|
@ -203,6 +209,12 @@ sub update {
|
|||
}
|
||||
);
|
||||
}
|
||||
elsif ( $_->isa('Koha::Exceptions::PayloadTooLarge') ) {
|
||||
return $c->render(
|
||||
status => 413,
|
||||
openapi => { error => $_->error }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$c->unhandled_exception($_);
|
||||
|
|
|
|||
Loading…
Reference in New Issue