Skip to content

Commit

Permalink
Update lambda file upload function to handle CSV files and other file…
Browse files Browse the repository at this point in the history
… types by returning the file size.
  • Loading branch information
perlDreamer committed Apr 19, 2024
1 parent 78dafd2 commit 59d2447
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ outline: deep

## 2024-04-19
* Fixed a problem where the default values set by a parent on child records wasn't being respected.
* Update lambda file upload function to handle CSV files and other file types by returning the file size.

## 2024-04-18
* Cast result of sum() and avg() to number.
Expand Down Expand Up @@ -91,4 +92,4 @@ outline: deep
* Added pseudo props to Records so that in addition to `user.set('admin', true)` you can also do `user.admin = true` for both setters and getters.

## 2024-03-12
* Fixed a security bug where passwords created via the CLI were stored incorrectly.
* Fixed a security bug where passwords created via the CLI were stored incorrectly.
10 changes: 9 additions & 1 deletion pulumi/aws/lambda/func/processUpload/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const handler = async (event) => {
out = formatResponse(await getZipInfo(url));
}
else {
out = formatError(`File type ${fileType} cannot be processed by this service.`);
out = formatResponse(await getOtherFileInfo(url));
}
}
catch (e) {
Expand Down Expand Up @@ -85,6 +85,14 @@ async function getZipInfo(url) {
return out;
}

async function getOtherFileInfo(url) {
const filePath = await downloadFile(url);
if (!fs.existsSync(filePath))
return formatError(`Could not download file from ${url}`);
const out = { sizeInBytes: getFileSize(filePath) };
return out;
}

async function getImageInfo(url, thumbnailKey) {
const filePath = await downloadFile(url);
if (!fs.existsSync(filePath))
Expand Down

0 comments on commit 59d2447

Please sign in to comment.