Skip to content

Commit

Permalink
Add metadata support for file uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
usualdesigner committed Mar 1, 2024
1 parent d5012be commit 1b4abaa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ describe("Main test suite", () => {
return "test";
case "file":
return "file.txt";
case "metadata":
return '{"key1": "value1", "key2": "value2"}';
default:
return "";
}
Expand Down
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.

10 changes: 10 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const handleInput = (): {
endpoint?: string;
acl?: ObjectCannedACL;
prefix?: string;
metaData?: Record<string, string>;
} => {
const bucketName = core.getInput("bucket-name", {
required: true,
Expand Down Expand Up @@ -51,6 +52,12 @@ const handleInput = (): {
required: false,
});

const metaData = core.getInput("metadata", {
required: false,
});

const metaDataObject = JSON.parse(metaData);

return {
bucketName,
file,
Expand All @@ -60,6 +67,7 @@ const handleInput = (): {
...(endpoint ? { endpoint } : {}),
...(acl ? { acl } : {}),
...(prefix ? { prefix } : {}),
...(metaData ? { metaData: metaDataObject } : {}),
};
};

Expand All @@ -79,6 +87,7 @@ export const run = async (): Promise<void> => {
acl,
prefix,
file,
metaData,
} = handleInput();

const s3Client = new S3Client({
Expand All @@ -102,6 +111,7 @@ export const run = async (): Promise<void> => {
ContentLength: fs.statSync(file).size,
ContentMD5: getMd5(file),
...(mime_type ? { ContentType: mime_type } : {}),
...(metaData ? { Metadata: metaData } : {}),
});

try {
Expand Down

0 comments on commit 1b4abaa

Please sign in to comment.