Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{
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.

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading