def create_many(self, files: list[InMemoryUploadedFile]) -> list[File]:
if not files:
return []
if len(files) > BATCH_SIZE_MAX:
message = f'Cannot upload more than {BATCH_SIZE_MAX} files at once.'
raise FileBatchLimitError(message)
for file in files:
self.validator.validate(file)
built = [self._build_file_record(file) for file in files]
try:
return File.objects.bulk_create(built)
except Exception:
for file_obj in built:
try:
file_obj.file.delete(save=False)
except Exception:
logger.exception('Failed to clean up storage orphan: %s', file_obj.file.name)
raise