Skip to content

Commit

Permalink
Update main.ts to calculate and set the ContentMD5 for S3 objects.- C…
Browse files Browse the repository at this point in the history
…alculate the MD5 hash of the file content using the crypto library.- Set the ContentMD5 property of the PutObjectCommand using the calculated MD5 hash.This commit includes changes to main.ts to calculate and set the ContentMD5 for S3 objects
  • Loading branch information
usualdesigner committed Feb 9, 2024
1 parent 7d5fbd5 commit 91123e2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from "fs";
import * as mime from "mime-types";
import * as core from "@actions/core";
import { createHash } from "crypto";
import {
S3Client,
PutObjectCommand,
Expand Down Expand Up @@ -62,6 +63,12 @@ const handleInput = (): {
};
};

const getMd5 = (fileName: string): string => {
const hasher = createHash("md5");
hasher.update(fs.readFileSync(fileName));
return hasher.digest("base64");
};

export const run = async (): Promise<void> => {
const {
accessKeyId,
Expand Down Expand Up @@ -93,7 +100,7 @@ export const run = async (): Promise<void> => {
Body: fs.readFileSync(file),
ACL: acl,
ContentLength: fs.statSync(file).size,
ContentMD5: fs.readFileSync(file).toString("base64"),
ContentMD5: getMd5(file),
...(mime_type ? { ContentType: mime_type } : {}),
});

Expand Down

0 comments on commit 91123e2

Please sign in to comment.