Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file size limit for upload/ingest (optional and configurable) #4387

Merged
merged 5 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ abstract class CommonConfig(resources: GridConfigResources) extends AwsClientV1B
val maybeIngestBucket: Option[String] = stringOpt("s3.ingest.bucket")
val maybeFailBucket: Option[String] = stringOpt("s3.fail.bucket")

val maybeUploadLimitInBytes: Option[Int] = intOpt("upload.limit.mb").map(_ * 1_000_000)

// Note: had to make these lazy to avoid init order problems ;_;
val domainRoot: String = string("domain.root")
val domainRootOverride: Option[String] = stringOpt("domain.root-override")
Expand Down
14 changes: 13 additions & 1 deletion image-loader/app/controllers/ImageLoaderController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,19 @@ class ImageLoaderController(auth: Authentication,

val approximateReceiveCount = getApproximateReceiveCount(sqsMessage)

if (approximateReceiveCount > 2) {
if(config.maybeUploadLimitInBytes.exists(_ < s3IngestObject.contentLength)){
val errorMessage = s"File size exceeds the maximum allowed size (${config.maybeUploadLimitInBytes.get / 1_000_000}MB). Moving to fail bucket."
logger.warn(logMarker, errorMessage)
store.moveObjectToFailedBucket(s3IngestObject.key)
s3IngestObject.maybeMediaIdFromUiUpload foreach { imageId =>
uploadStatusTable.updateStatus( // fire & forget, since there's nothing else we can do
imageId, UploadStatus(StatusType.Failed, Some(errorMessage))
)
}
metrics.failedIngestsFromQueue.incrementBothWithAndWithoutDimensions(metricDimensions)
Future.unit
twrichards marked this conversation as resolved.
Show resolved Hide resolved
}
else if (approximateReceiveCount > 2) {
metrics.abandonedMessagesFromQueue.incrementBothWithAndWithoutDimensions(metricDimensions)
val errorMessage = s"File processing has been attempted $approximateReceiveCount times. Moving to fail bucket."
logger.warn(logMarker, errorMessage)
Expand Down
1 change: 1 addition & 0 deletions kahuna/app/views/main.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
permissionsDefault: "@kahunaConfig.permissionsDefault",
defaultShouldBlurGraphicImages: @kahunaConfig.defaultShouldBlurGraphicImages,
shouldUploadStraightToBucket: @kahunaConfig.shouldUploadStraightToBucket,
maybeUploadLimitInBytes: @kahunaConfig.maybeUploadLimitInBytes,
announcements: @Html(announcements),
imageTypes: @Html(imageTypes),
}
Expand Down
16 changes: 15 additions & 1 deletion kahuna/public/js/upload/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,21 @@ upload.factory('uploadManager',
};
}

async function createJobItems(files){
async function createJobItems(_files){

const maybeUploadLimitInBytes = window._clientConfig.maybeUploadLimitInBytes;
const maybeFilesAboveSizeLimit = !!maybeUploadLimitInBytes && _files.filter(file => file.size > maybeUploadLimitInBytes);

if (maybeFilesAboveSizeLimit && maybeFilesAboveSizeLimit.length > 0){
alert(`The following files will be skipped as they are above the size limit of ${maybeUploadLimitInBytes / 1_000_000}MB:\n${
maybeFilesAboveSizeLimit.map(file => file.name).join("\n")
}`);
}

const files = maybeFilesAboveSizeLimit && maybeFilesAboveSizeLimit.length > 0
? _files.filter(file => !maybeFilesAboveSizeLimit.includes(file))
: _files;

if (window._clientConfig.shouldUploadStraightToBucket) {
const mediaIdToFileMap = Object.fromEntries(
await Promise.all(
Expand Down
Loading