the @aws-sdk/client-s3 library does not provide a direct upload method

the @aws-sdk/client-s3 library does not provide a direct upload method

By medeb | personalblog | 14 May 2025


1. The property "upload" does not exist on the type "S3Client"
The error "The property "upload" does not exist on the type "S3Client"" indicates that you are trying to use a method named upload on an S3Client instance,
but the @aws-sdk/client-s3 library does not provide a direct upload method. Therefore, you should use PutObjectCommand for simple uploads, or the higher-level @aws-sdk/lib-storage package for more complex uploads (especially large files).
You should correct your code by using the appropriate methods.
2. Simple uploads with PutObjectCommand:
TypeScript
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3'; async function uploadToS3(bucketName: string, key: string, body: any) {
const s3Client = new S3Client({}); // Configure your client here
const params = {
Bucket: bucketName,
Key:key,
Bodysuit: bodysuit,
};
try {
const command = new PutObjectCommand(params);
const result = await s3Client.send(command);
console.log('Upload successful:', result);
return `s3://${bucketName}/${key}`; // Return the S3 URL
} catch (error) {
console.error('Error downloading to S3:', error);
return null;
}
}
3. Example of use:
async function yourFunction() {
const bucketName = 'your-bucket-name';
const key = 'your-object-key.txt';
const body = 'Hello S3!';
const s3Url = await uploadToS3(bucketName, key, body);
if (s3Url) {
console.log('S3 URL:', s3Url);
} else {
// Handle upload failure
}
}
yourFunction();

d7fadb6d4fe06f86935a3540e43d8c6afd5f2d4c8bd97f8b4aebde60d1ddc67f.png

How do you rate this article?

2



personalblog
personalblog

My daily experience in crypto world

Publish0x

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.