인터넷에서이 파일을 사용하여 Amazon S3 서버에 여러 파일을 업로드했습니다.비동기 작업이 완료되면 알림 받기
const AWS = require("aws-sdk"); // from AWS SDK
const fs = require("fs"); // from node.js
const path = require("path"); // from node.js
// configuration
const config = {
s3BucketName: 'your.s3.bucket.name',
folderPath: '../dist' // path relative script's location
};
// initialize S3 client
const s3 = new AWS.S3({ signatureVersion: 'v4' });
// resolve full folder path
const distFolderPath = path.join(__dirname, config.folderPath);
// get of list of files from 'dist' directory
fs.readdir(distFolderPath, (err, files) => {
if(!files || files.length === 0) {
console.log(`provided folder '${distFolderPath}' is empty or does not exist.`);
console.log('Make sure your project was compiled!');
return;
}
// for each file in the directory
for (const fileName of files) {
// get the full path of the file
const filePath = path.join(distFolderPath, fileName);
// ignore if directory
if (fs.lstatSync(filePath).isDirectory()) {
continue;
}
// read file contents
fs.readFile(filePath, (error, fileContent) => {
// if unable to read file contents, throw exception
if (error) { throw error; }
// upload file to S3
s3.putObject({
Bucket: config.s3BucketName,
Key: fileName,
Body: fileContent
}, (res) => {
console.log(`Successfully uploaded '${fileName}'!`);
});
});
}
});
다른 프로세스를 실행하기 위해 업로드가 완료되었음을 어떻게 알릴 수 있습니까? 단일 파일이 성공적으로 업로드되면 res가 호출됩니다.
왜하지 다른 프로세스를 실행하기 위해 알림을 res로 사용 하시겠습니까? – SILENT
새로운 파일이 업로드 될 때마다 res가 호출됩니다. – doej
그래서? 모든 업로드가 완료된 후 질문에 대한 알림이 필요합니까? – SILENT