Answer the question
In order to leave comments, you need to log in
Why is AWS throwing an error?
import { Injectable } from '@nestjs/common';
import aws from 'aws-sdk';
import { UploadTaskFilesDto } from './dto/uploadTaskFiles.dto';
@Injectable()
export class FileUploadService {
async uploadTaskFile(uploadTaskFilesDto: UploadTaskFilesDto) {
const s3 = new aws.S3({
region: 'eu-central-1',
accessKeyId: process.env.AWS_ACCESS_KEY,
secretAccessKey: process.env.AWS_SECRET,
signatureVersion: 'v4',
});
const uploadUrls: string[] = [];
for (let i = 0; i < uploadTaskFilesDto.files.length; i++) {
const file = uploadTaskFilesDto.files[i];
const params = {
Bucket: 'bucket',
Key: `${file.name}`,
Expires: 60,
};
await s3.getSignedUrlPromise('putObject', params).then((url) => {
uploadUrls.push(url);
});
}
return uploadUrls;
}
}
TypeError: Cannot read properties of undefined (reading 'S3')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question