S
S
Snoz3f2022-03-02 17:48:17
JavaScript
Snoz3f, 2022-03-02 17:48:17

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;
  }
}

Greetings, I have the following code (given above). Before that, it worked, but at one moment it simply stopped, while nothing changed in the code. Started throwing an error at the S3 initialization stage

TypeError: Cannot read properties of undefined (reading 'S3')


What could be the reason for this error? I reinstalled the packages, again, everything worked correctly before that

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Snoz3f, 2022-03-07
@Snoz3f

As mentioned above, we changed api, now you can import only with destructuring

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question