File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import { BUCKET_NAME , s3Client } from '@/app/s3' ;
44import { logger } from '@/utils/logger' ;
5+
6+ // This log will run as soon as the module is loaded.
7+ logger . info ( '[uploadFile] Module loaded.' ) ;
8+
59import { GetObjectCommand , PutObjectCommand } from '@aws-sdk/client-s3' ;
610import { getSignedUrl } from '@aws-sdk/s3-request-presigner' ;
711import { AttachmentEntityType , AttachmentType , db } from '@db' ;
Original file line number Diff line number Diff line change @@ -20,13 +20,24 @@ if (!APP_AWS_ACCESS_KEY_ID || !APP_AWS_SECRET_ACCESS_KEY || !BUCKET_NAME || !APP
2020
2121// Create a single S3 client instance
2222// Add null checks or assertions if the checks above don't guarantee non-null values
23- export const s3Client = new S3Client ( {
24- region : APP_AWS_REGION ! ,
25- credentials : {
26- accessKeyId : APP_AWS_ACCESS_KEY_ID ! ,
27- secretAccessKey : APP_AWS_SECRET_ACCESS_KEY ! ,
28- } ,
29- } ) ;
23+
24+ export const s3Client = new S3Client (
25+ // If we are on Vercel, we MUST provide explicit credentials.
26+ process . env . VERCEL === '1'
27+ ? {
28+ region : APP_AWS_REGION ! ,
29+ credentials : {
30+ accessKeyId : APP_AWS_ACCESS_KEY_ID ! ,
31+ secretAccessKey : APP_AWS_SECRET_ACCESS_KEY ! ,
32+ } ,
33+ }
34+ : // For any other environment (like AWS ECS or local dev),
35+ // we only need to provide the region. The AWS SDK will
36+ // automatically find the credentials from the environment.
37+ {
38+ region : APP_AWS_REGION ! ,
39+ } ,
40+ ) ;
3041
3142// Ensure BUCKET_NAME is exported and non-null checked if needed elsewhere explicitly
3243if ( ! BUCKET_NAME && process . env . NODE_ENV === 'production' ) {
Original file line number Diff line number Diff line change @@ -21,13 +21,23 @@ if (!APP_AWS_ACCESS_KEY_ID || !APP_AWS_SECRET_ACCESS_KEY || !BUCKET_NAME || !APP
2121
2222// Create a single S3 client instance
2323// Add null checks or assertions if the checks above don't guarantee non-null values
24- export const s3Client = new S3Client ( {
25- region : APP_AWS_REGION ! ,
26- credentials : {
27- accessKeyId : APP_AWS_ACCESS_KEY_ID ! ,
28- secretAccessKey : APP_AWS_SECRET_ACCESS_KEY ! ,
29- } ,
30- } ) ;
24+ export const s3Client = new S3Client (
25+ // If we are on Vercel, we MUST provide explicit credentials.
26+ process . env . VERCEL === '1'
27+ ? {
28+ region : APP_AWS_REGION ! ,
29+ credentials : {
30+ accessKeyId : APP_AWS_ACCESS_KEY_ID ! ,
31+ secretAccessKey : APP_AWS_SECRET_ACCESS_KEY ! ,
32+ } ,
33+ }
34+ : // For any other environment (like AWS ECS or local dev),
35+ // we only need to provide the region. The AWS SDK will
36+ // automatically find the credentials from the environment.
37+ {
38+ region : APP_AWS_REGION ! ,
39+ } ,
40+ ) ;
3141
3242// Ensure BUCKET_NAME is exported and non-null checked if needed elsewhere explicitly
3343if ( ! BUCKET_NAME && process . env . NODE_ENV === 'production' ) {
You can’t perform that action at this time.
0 commit comments