Skip to content

Add Upload construct#103

Open
t-richard wants to merge 3 commits intogetlift:masterfrom
t-richard:upload-construct
Open

Add Upload construct#103
t-richard wants to merge 3 commits intogetlift:masterfrom
t-richard:upload-construct

Conversation

@t-richard
Copy link
Copy Markdown
Contributor

@t-richard t-richard commented Sep 26, 2021

See the docs for explanations.

  • More tests
  • Document what is done with CORS ?
  • Axios example ?
  • in depth explanation of wha the function does ?
  • example code for backend processing ?

type: "object",
properties: {
type: { const: "storage" },
archive: { type: "number", minimum: 30 },
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was unused in the construct


exports.handler = async (event) => {
const body = JSON.parse(event.body);
const fileName = \`tmp/\${crypto.randomBytes(5).toString('hex')}-\${body.fileName}\`;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this generates a random file name to avoid collisions by adding a random hash before the submitted filename.

cors: [
{
allowedMethods: [HttpMethods.PUT],
allowedOrigins: ["*"],
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this first version I chose to set wide CORS permissions. We may add an option to configure it later.


outputs(): Record<string, () => Promise<string | undefined>> {
return {
bucketName: () => this.getBucketName(),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice to output the full upload URL but I wasn't able to generate it properly for Rest APIs. Another problem was that people may have domains configured on their API Gateway or they may be using the server-side construct which woul make the outputed URL useless.

@t-richard
Copy link
Copy Markdown
Contributor Author

See some working examples here https://github.com/t-richard/lift-upload-example

Steps to deploy it are in the README

@tschoffelen
Copy link
Copy Markdown

This is really cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants