|
|
@@ -63,6 +63,7 @@ export class S3Service {
|
|
|
const key = `${folder}/${Date.now()}_${Math.random().toString(36).slice(2, 8)}.${ext}`;
|
|
|
|
|
|
const maxSize = this.resolveMaxSize(contentType);
|
|
|
+ this.logger.log(`maxSize for upload: ${maxSize} bytes`);
|
|
|
|
|
|
const { url, fields } = await createPresignedPost(this.s3, {
|
|
|
Bucket: this.bucket,
|
|
|
@@ -81,13 +82,25 @@ export class S3Service {
|
|
|
}
|
|
|
|
|
|
private resolveMaxSize(contentType: string): number {
|
|
|
+ this.logger.log(`Resolving max size for content type: ${contentType}`);
|
|
|
+ const BASE64_OVERHEAD_RATIO = 4 / 3; // ≈1.333
|
|
|
+ const SAFETY_MARGIN = 1.05; // extra 5% for headers / future changes
|
|
|
+
|
|
|
const fromEnvMB = (env: string, fallbackMB: number) => {
|
|
|
const val = Number(process.env[env]);
|
|
|
return (isNaN(val) ? fallbackMB : val) * 1024 * 1024;
|
|
|
};
|
|
|
|
|
|
+ // ✅ your image payload is base64 text
|
|
|
+ if (contentType === 'text/plain') {
|
|
|
+ const rawMb = Number(process.env.UPLOAD_LIMIT_IMAGE ?? 10);
|
|
|
+ const effectiveMb = rawMb * (4 / 3) * 1.05;
|
|
|
+ return Math.ceil(effectiveMb * 1024 * 1024);
|
|
|
+ }
|
|
|
if (contentType.startsWith('image/')) {
|
|
|
- return fromEnvMB('UPLOAD_LIMIT_IMAGE', 20);
|
|
|
+ const rawMb = Number(process.env.UPLOAD_LIMIT_IMAGE ?? 10);
|
|
|
+ const effectiveMb = rawMb * BASE64_OVERHEAD_RATIO * SAFETY_MARGIN;
|
|
|
+ return Math.ceil(effectiveMb * 1024 * 1024);
|
|
|
}
|
|
|
if (contentType === 'video/mp4') {
|
|
|
return fromEnvMB('UPLOAD_LIMIT_VIDEO', 100);
|