@@ -6,7 +6,7 @@ const zlib = require('zlib');
6
6
const { Buffer } = require ( 'buffer' ) ;
7
7
const { promisify } = require ( 'util' ) ;
8
8
9
- const AWS = require ( 'aws-sdk' ) ;
9
+ const { S3Client , PutObjectCommand } = require ( '@ aws-sdk/client-s3 ' ) ;
10
10
const sharp = require ( 'sharp' ) ;
11
11
const _ = require ( 'lodash' ) ;
12
12
const debug = require ( 'debug' ) ( 'nodemailer-base64-to-s3' ) ;
@@ -46,14 +46,7 @@ const base64ToS3 = (options = {}) => {
46
46
if ( _ . startsWith ( opts . dir , '/' ) ) opts . dir = opts . dir . slice ( 1 ) ;
47
47
48
48
// prepare AWS upload using config
49
- const s3 = new AWS . S3 ( opts . aws ) ;
50
-
51
- // we cannot currently use this since it does not return a promise
52
- // <https://github.com/aws/aws-sdk-js/pull/1079>
53
- // await s3obj.upload({ Body }).promise();
54
- //
55
- // so instead we use promisify to convert it to a promise
56
- const upload = promisify ( s3 . upload ) . bind ( s3 ) ;
49
+ const s3Client = new S3Client ( opts . aws ) ;
57
50
58
51
async function compile ( mail , fn ) {
59
52
try {
@@ -124,6 +117,7 @@ const base64ToS3 = (options = {}) => {
124
117
const Key = `${ opts . dir } ${ fileName } ` ;
125
118
126
119
const obj = {
120
+ ...opts . aws . params ,
127
121
Key,
128
122
ACL : 'public-read' ,
129
123
Body,
@@ -135,7 +129,9 @@ const base64ToS3 = (options = {}) => {
135
129
// use a fallback dir if the upload fails
136
130
// but only if the environment is not production
137
131
try {
138
- const data = cache [ Key ] ? cache [ Key ] : await upload ( obj ) ;
132
+ const data = cache [ Key ]
133
+ ? cache [ Key ]
134
+ : await s3Client . send ( new PutObjectCommand ( obj ) ) ;
139
135
if ( cache [ Key ] ) debug ( `hitting cache for ${ Key } ` ) ;
140
136
141
137
const replacement = isSANB ( opts . cloudFrontDomainName )
0 commit comments