-
Notifications
You must be signed in to change notification settings - Fork 112
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
base: master
Are you sure you want to change the base?
Add Upload construct #103
Conversation
d418f94
to
e093eb5
Compare
@@ -10,7 +10,6 @@ const STORAGE_DEFINITION = { | |||
type: "object", | |||
properties: { | |||
type: { const: "storage" }, | |||
archive: { type: "number", minimum: 30 }, |
There was a problem hiding this comment.
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}\`; |
There was a problem hiding this comment.
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: ["*"], |
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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.
See some working examples here https://github.com/t-richard/lift-upload-example Steps to deploy it are in the README |
0923fa8
to
b0d4e35
Compare
This is really cool! |
b0d4e35
to
41e89d5
Compare
See the docs for explanations.