Skip to content

Commit

Permalink
Update script, AWS_S3Client
Browse files Browse the repository at this point in the history
  • Loading branch information
NguyenAnhTuan1912 committed Aug 20, 2024
1 parent e8868bf commit 546288a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
3 changes: 3 additions & 0 deletions backend/nodejs/scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ cd /home/backend/nodejs
export PYTHON_PATH="/home/backend/python/venv/bin/python"
export TEMP_PATH="/home/backend/temp"
export UPLOADS_PATH="/home/backend/uploads"

## Setup AWS Resource Information
export AWS_REGION="your_region"
export BUCKET_NAME="your_bucket_name"

# Start NodeJS Server
Expand Down
12 changes: 7 additions & 5 deletions backend/nodejs/src/classes/AWS_S3Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {

export class AWS_S3Client {
constructor() {
this._client = new S3Client();
this._client = new S3Client({
region: process.env.AWS_REGION,
});
}

async upload(bucketName, name, objectPath) {
Expand All @@ -31,8 +33,8 @@ export class AWS_S3Client {
return { result: data };
} catch (err) {
// Log the detailed error for troubleshooting
console.error("Error put objects:", JSON.stringify(err, null, 2));
return Promise.reject(null);
console.error("Error put objects:", err);
return Promise.reject(err);
}
}

Expand All @@ -58,8 +60,8 @@ export class AWS_S3Client {
return { objectKeys: objectKeys };
} catch (err) {
// Log the detailed error for troubleshooting
console.error("Error listing objects:", JSON.stringify(err, null, 2));
return Promise.reject(null);
console.error("Error listing objects:", err);
return Promise.reject(err);
}
}
}
6 changes: 1 addition & 5 deletions backend/nodejs/src/handlers/datatableImageToExcel.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ export const DatatableImageToExcelHandler = createHandler(

// Upload ảnh lên S3
s3Client
.upload(
bucketName,
image.filename,
path.resolve(image.path, image.filename)
)
.upload(bucketName, image.filename, path.resolve(image.path))
.then(() => {
console.log("Image in", image.path, "is uploaded to S3");
// Tải lên rồi thì xóa ảnh và file.
Expand Down
2 changes: 1 addition & 1 deletion gui/js/apis/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const API_ROOT = "http://ec2-47-129-229-78.ap-southeast-1.compute.amazonaws.com/api";
export const API_ROOT = "http://ec2-54-169-204-208.ap-southeast-1.compute.amazonaws.com/api";

0 comments on commit 546288a

Please sign in to comment.