我想使用multer-s3将图像从nestjs上传到AWS S3存储桶。
这是我编写代码以使用AWS S3进行配置的方式:
import * as multer from 'multer';<br>
import * as AWS from 'aws-sdk';<br>
import * as multerS3 from 'multer-s3';<br>
const AWS_S3_BUCKET_NAME = process.env.AWS_S3_BUCKET_NAME;<br>
const s3 = new AWS.S3();<br>
AWS.config.update({<br>
accessKeyId: process.env.AWS_ACCESS_KEY_ID,<br>
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,<br>
});
@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'))
@Post('/:hotelid')<br>
@UsePipes(ValidationPipe)
@UseInterceptors(
FilesInterceptor('file',5,{
storage: multerS3({
s3: s3,
bucket: AWS_S3_BUCKET_NAME,
acl: 'public-read',
key: function(request, file, cb) {
cb(null, `${Date.now().toString()} - ${file.originalname}`);
},
}),
fileFilter: imageFileFilter,
}),
)
createRoom(
@Req() req:any,
@Param('hotelid') id:number,
@UploadedFiles() file,
@Body() createRoomDto : CreateRoomDto,
):Promise<Room>
{
return this.roomsService.createRoom(req.user,createRoomDto,id,req.files);
}
这段代码工作正常,但我想使用AWS-SDK-JS-V3。
在AWS sdk-js-V3中,我无法使用AWS.config.update({....})
您能建议我如何将代码从aws-sdk-js v2更改为aws-sdk-js-v3吗?