imrankerimoglu
imrankerimoglu

Reputation: 11

AWS S3 nodejs config.endpointDiscoveryEnabled is not a function problem

When I try to upload photos to v3 aws-client s3 , I get an error as follows. How can I find the solution?

This is my code :

const  { S3Client, AbortMultipartUploadCommand } = require('@aws-sdk/client-s3');
const { TimestreamWriteClient, WriteRecordsCommand,EndpointDiscoveryEnabled } = require("@aws-sdk/client-timestream-write");

const client = new S3Client({
    endpointDiscoveryEnabled: undefined,
    region: 'eu-central-1',
    accessKeyId: 'access key',
    secretAccessKey: 'secret key',
});

return new Promise(resolve => {
            try {
            
                const base64Data = base64Image.replace(/^data:([A-Za-z-+/]+);base64,/, '');
                const type = base64Image.split(';')[0].split('/')[1];

                const newFileName = filename ? filename + (thumb === true ? '_thumb':'') + '.' + type : uuidv4() + (thumb === true ? '_thumb':'') + '.' + type;

                const imageBuffer = Buffer.from(base64Data, 'base64');

                const params = {
                    Bucket: "bucket123",
                    Key: "newFileName.png",
                    ACL: 'public-read',
                    Body: imageBuffer,
                    ContentEncoding: 'base64',
                    ContentType: type,

                };

                const command = new WriteRecordsCommand(params);

                client.send(command, function (err, data) {
                    if(!err) {
                        resolve({
                            status: true,
                            message: 'success'
                        });
                    } else {
                        resolve( {
                            status: false,
                            message: err
                        });
                    }
                });
            } catch (err) {
                resolve({
                    status: false,
                    message: err
                });
            }
        });

This is my problem:

{ status: false, message: TypeError: config.endpointDiscoveryEnabled is not a function at /Users/imrankarimov/Desktop/Project/WEB/rentsys-saas-api/node_modules/@aws-sdk/middleware-endpoint-discovery/dist-cjs/endpointDiscoveryMiddleware.js:17:53 at /Users/imrankarimov/Desktop/Project/WEB/rentsys-saas-api/node_modules/@aws-sdk/middleware-expect-continue/dist-cjs/index.js:14:16 at /Users/imrankarimov/Desktop/Project/WEB/rentsys-saas-api/node_modules/@smithy/middleware-content-length/dist-cjs/index.js:26:16 at /Users/imrankarimov/Desktop/Project/WEB/rentsys-saas-api/node_modules/@smithy/middleware-serde/dist-cjs/serializerMiddleware.js:13:12 at async /Users/imrankarimov/Desktop/Project/WEB/rentsys-saas-api/node_modules/@aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:7:26 }

I searched about the function that gave the error, but I couldn't find any results.

Upvotes: 0

Views: 365

Answers (1)

Filippo Testini
Filippo Testini

Reputation: 2306

endpointDiscoveryEnabled is not a property of the S3 client, but rather of the DynamoDB client.
Simply remove it from the client's constructor, and everything should work fine.

As a best practice, check also how you're passing your credentials: hardcoding the access key/secret directly into your code is not advisable.
Refer to the documentation to determine the most appropriate method depending on where your code is running.

Upvotes: 0

Related Questions