NeahNew/test-upload.js
2025-05-22 18:29:23 +02:00

36 lines
935 B
JavaScript

const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3');
const fs = require('fs');
const s3Config = {
endpoint: 'https://dome-api.slm-lab.net',
region: 'us-east-1',
credentials: {
accessKeyId: 'LwgeE1ntADD20OuWC88S3pR0EaO7FtO4',
secretAccessKey: 'gbdrqJsXyU4IFxsfz9xdrnQeMRy2eZHeqQRrAeBR'
},
forcePathStyle: true
};
const s3Client = new S3Client(s3Config);
async function uploadFile() {
try {
const fileContent = fs.readFileSync('/Users/alma/Documents/test.png');
const command = new PutObjectCommand({
Bucket: 'missions',
Key: 'test-mission/logo.png',
Body: fileContent,
ContentType: 'image/png',
ACL: 'public-read'
});
console.log('Uploading file...');
const response = await s3Client.send(command);
console.log('Upload successful!', response);
} catch (error) {
console.error('Error uploading file:', error);
}
}
uploadFile();