Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Upload construct #103

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

t-richard
Copy link
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 ?

@@ -10,7 +10,6 @@ const STORAGE_DEFINITION = {
type: "object",
properties: {
type: { const: "storage" },
archive: { type: "number", minimum: 30 },
Copy link
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
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
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
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
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

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.

None yet

2 participants