yikart/AiToEarn · warning · AppException

ResponseCode.AssetTooLarge

ResponseCode.AssetTooLarge

Error message

AssetTooLarge

What it means

createUploadSign validates the client-declared dto.size against options.maxSize before signing an upload and throws AssetTooLarge when the declared size is >= maxSize. It prevents issuing upload credentials for assets exceeding the quota.

Source

Thrown at project/aitoearn-backend/libs/assets/src/assets.service.ts:41

@Injectable()
export class AssetsService {
  private readonly logger = new Logger(AssetsService.name)

  constructor(
    private readonly storage: StorageProvider,
    private readonly assetRepository: AssetRepository,
    private readonly videoMetadataService: VideoMetadataService,
    @Inject(ASSETS_CONFIG) protected readonly options: AssetsConfig,
  ) {}

  async createUploadSign(
    userId: string,
    dto: UploadAssetDto,
    userType: UserType = UserType.User,
  ): Promise<Required<UploadResult>> {
    if (this.options.maxSize != null && dto.size && dto.size >= this.options.maxSize) {
      throw new AppException(ResponseCode.AssetTooLarge)
    }
    const pathOptions: PathGeneratorOptions = {
      userId,
      userType,
      type: dto.type,
      mimeType: dto.mimeType,
      filename: dto.filename,
    }

    const path = generateAssetPath(pathOptions)

    const asset = await this.assetRepository.create({
      userId,
      userType,
      path,
      type: dto.type,
      status: AssetStatus.Pending,
      size: dto.size,

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Reduce the file size or compress it client-side before requesting an upload sign
  2. Raise options.maxSize in the module/service configuration if the limit is too strict for the asset type
  3. Verify dto.size is in bytes and matches the actual file
  4. Check whether the user's plan/tier should allow a larger maxSize

Example fix

// before
await createUploadSign(userId, { size: 60 * 1024 * 1024, type, mimeType }) // 60MB > 50MB limit
// after
await createUploadSign(userId, { size: 40 * 1024 * 1024, type, mimeType }) // within limit
Defensive patterns

Strategy: validation

Validate before calling

const MAX = 50 * 1024 * 1024
if (file.size >= MAX) throw new Error(`File ${file.size} bytes exceeds ${MAX} byte limit`)
await createUploadSign(userId, { size: file.size, type, mimeType })

Type guard

function withinSizeLimit(dto: { size?: number }, maxSize?: number | null): boolean {
  return maxSize == null || !dto.size || dto.size < maxSize
}

Try / catch

try {
  const sign = await createUploadSign(userId, dto)
} catch (e) {
  if (e.code === ResponseCode.AssetTooLarge) {
    // surface a friendly 'file too large' message / offer compression
  }
  throw e
}

Prevention

When it happens

Trigger: Client calls the upload-sign endpoint with UploadAssetDto.size greater than or equal to the configured maxSize (e.g. uploading a video larger than the plan's limit).

Common situations: Client computes size incorrectly (bytes vs MB), maxSize configured lower than expected for the asset type, mobile clients uploading large videos/photos, or dto.size sent in a different unit.

Related errors


AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31). Data as JSON: /api/errors/7f5c85ef1c1fcace. Report an issue: GitHub.