{"record":{"id":"7f5c85ef1c1fcace","repo":"yikart/AiToEarn","slug":"responsecode-assettoolarge","errorCode":"ResponseCode.AssetTooLarge","errorMessage":"AssetTooLarge","messagePattern":"AssetTooLarge","errorType":"error_code","errorClass":"AppException","httpStatus":null,"severity":"warning","filePath":"project/aitoearn-backend/libs/assets/src/assets.service.ts","lineNumber":41,"sourceCode":"\n@Injectable()\nexport class AssetsService {\n  private readonly logger = new Logger(AssetsService.name)\n\n  constructor(\n    private readonly storage: StorageProvider,\n    private readonly assetRepository: AssetRepository,\n    private readonly videoMetadataService: VideoMetadataService,\n    @Inject(ASSETS_CONFIG) protected readonly options: AssetsConfig,\n  ) {}\n\n  async createUploadSign(\n    userId: string,\n    dto: UploadAssetDto,\n    userType: UserType = UserType.User,\n  ): Promise<Required<UploadResult>> {\n    if (this.options.maxSize != null && dto.size && dto.size >= this.options.maxSize) {\n      throw new AppException(ResponseCode.AssetTooLarge)\n    }\n    const pathOptions: PathGeneratorOptions = {\n      userId,\n      userType,\n      type: dto.type,\n      mimeType: dto.mimeType,\n      filename: dto.filename,\n    }\n\n    const path = generateAssetPath(pathOptions)\n\n    const asset = await this.assetRepository.create({\n      userId,\n      userType,\n      path,\n      type: dto.type,\n      status: AssetStatus.Pending,\n      size: dto.size,","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-backend/libs/assets/src/assets.service.ts#L23-L59","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Reduce the file size or compress it client-side before requesting an upload sign","Raise options.maxSize in the module/service configuration if the limit is too strict for the asset type","Verify dto.size is in bytes and matches the actual file","Check whether the user's plan/tier should allow a larger maxSize"],"exampleFix":"// before\nawait createUploadSign(userId, { size: 60 * 1024 * 1024, type, mimeType }) // 60MB > 50MB limit\n// after\nawait createUploadSign(userId, { size: 40 * 1024 * 1024, type, mimeType }) // within limit","handlingStrategy":"validation","validationCode":"const MAX = 50 * 1024 * 1024\nif (file.size >= MAX) throw new Error(`File ${file.size} bytes exceeds ${MAX} byte limit`)\nawait createUploadSign(userId, { size: file.size, type, mimeType })","typeGuard":"function withinSizeLimit(dto: { size?: number }, maxSize?: number | null): boolean {\n  return maxSize == null || !dto.size || dto.size < maxSize\n}","tryCatchPattern":"try {\n  const sign = await createUploadSign(userId, dto)\n} catch (e) {\n  if (e.code === ResponseCode.AssetTooLarge) {\n    // surface a friendly 'file too large' message / offer compression\n  }\n  throw e\n}","preventionTips":["Check file.size client-side against the documented limit before upload","Ensure size is expressed in bytes consistently","Align maxSize config with product limits per asset type","Offer client-side compression for media over the limit"],"tags":["upload","validation","file-size","assets"],"backgroundTag":"asset-too-large","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}