wuyiqun0718 commited on
Commit
5b99fc6
1 Parent(s): 2d611fd

fix: aws token expired issue

Browse files
Files changed (2) hide show
  1. app/api/upload/route.ts +1 -1
  2. lib/aws.ts +3 -8
app/api/upload/route.ts CHANGED
@@ -43,7 +43,7 @@ export async function POST(req: Request): Promise<Response> {
43
  console.log('Image uploaded successfully');
44
  urlToSave = `https://${process.env.AWS_BUCKET_NAME}.s3.${process.env.AWS_REGION}.amazonaws.com/${fileName}`;
45
  } else {
46
- throw new Error('Failed to upload image');
47
  }
48
  }
49
 
 
43
  console.log('Image uploaded successfully');
44
  urlToSave = `https://${process.env.AWS_BUCKET_NAME}.s3.${process.env.AWS_REGION}.amazonaws.com/${fileName}`;
45
  } else {
46
+ return res;
47
  }
48
  }
49
 
lib/aws.ts CHANGED
@@ -2,19 +2,14 @@ import { createPresignedPost } from '@aws-sdk/s3-presigned-post';
2
  import { S3Client } from '@aws-sdk/client-s3';
3
  import { fromEnv } from '@aws-sdk/credential-providers';
4
 
 
 
5
  const s3Client = new S3Client({
6
  region: process.env.AWS_REGION,
7
  credentials: fromEnv(),
8
  });
9
 
10
- const FILE_SIZE_LIMIT = 10485760; // 10MB
11
-
12
- export const upload = async (
13
- base64: string,
14
- fileName: string,
15
- fileType: string,
16
- ) => {
17
- const imageBuffer = Buffer.from(base64, 'base64');
18
  const { url, fields } = await createPresignedPost(s3Client, {
19
  Bucket: process.env.AWS_BUCKET_NAME ?? 'vision-agent-dev',
20
  Key: fileName,
 
2
  import { S3Client } from '@aws-sdk/client-s3';
3
  import { fromEnv } from '@aws-sdk/credential-providers';
4
 
5
+ const FILE_SIZE_LIMIT = 10485760; // 10MB
6
+
7
  const s3Client = new S3Client({
8
  region: process.env.AWS_REGION,
9
  credentials: fromEnv(),
10
  });
11
 
12
+ export const upload = async (base64: string, fileName: string, fileType: string) => {
 
 
 
 
 
 
 
13
  const { url, fields } = await createPresignedPost(s3Client, {
14
  Bucket: process.env.AWS_BUCKET_NAME ?? 'vision-agent-dev',
15
  Key: fileName,