EXCEED_MAX_RESPONSE_SIZE
Encountering an error? Get help with AI tools
Error Cause
Response size exceeds maximum response limit. CloudBase related API response limits are:
- Mini program link maximum response body: 1 MB
- Cloud function maximum response body: 6MB
- Document database query maximum response body: 50 MB
Solution
1. Use paginated queries
For large amounts of data, use pagination to retrieve data in batches:
// Database query pagination example
const pageSize = 100;
const page = 1;
const result = await db
.collection("users")
.skip((page - 1) * pageSize)
.limit(pageSize)
.get();
2. Simplify return fields
Only return necessary fields, avoid returning entire document:
// Only select needed fields
const result = await db
.collection("users")
.field({
name: true,
email: true,
avatar: true,
// Don't return large fields like description, content etc
})
.get();
3. Use cloud storage for large data transfer
For very large data (such as export functionality), it's recommended to first write data to cloud storage, then return download link:
import cloudbase from "@cloudbase/node-sdk";
const app = cloudbase.init({
env: "your-env-id", // Replace with your environment id
region: "ap-shanghai", // Defaults to Shanghai region if not provided
});
exports.main = async (event, context) => {
// Generate large amount of data
const largeData = await generateLargeData();
// Upload to cloud storage
const fileName = `export_${Date.now()}.json`;
await app.uploadFile({
cloudPath: `exports/${fileName}`,
fileContent: JSON.stringify(largeData),
});
// Get temporary download link
const result = await cloud.getTempFileURL({
fileList: [`exports/${fileName}`],
});
// Return download link
return {
downloadUrl: result.fileList[0].tempFileURL,
};
};