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
- 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
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
- 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
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
- ResponseCode.AssetNotFound
- Invalid public upload id
- accountId和视频大小是必须的
- 初始化响应缺少 publish_id 或 upload_url
- No subtitle entries in response
AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31).
Data as JSON: /api/errors/7f5c85ef1c1fcace.
Report an issue: GitHub.