This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "Version": "2012-10-17", | |
| "Id": "Policy1532447175542", | |
| "Statement": [ | |
| { | |
| "Effect": "Allow", | |
| "Principal": "*", | |
| "Action": "s3:putObject", | |
| "Resource": "arn:aws:s3:::YOUR-BUCKET-NAME/*" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <form onSubmit={this.submitFile}> | |
| <input | |
| label="Upload file" | |
| type="file" | |
| onChange={this.handleFileUpload} | |
| /> | |
| <button type="submit">Upload</button> | |
| </form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| handleFileUpload = (event) => { | |
| this.setState({ file: event.target.files }); | |
| }; | |
| submitFile = (event) => { | |
| event.preventDefault(); | |
| const formData = new FormData(); | |
| formData.append('file', this.state.file[0]); | |
| axios | |
| .post( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const getContentType = (event) => { | |
| const contentType = event.headers['content-type'] | |
| if (!contentType) { | |
| return event.headers['Content-Type']; | |
| } | |
| return contentType; | |
| }; | |
| const parser = (event) => new Promise((resolve, reject) => { | |
| const busboy = new Busboy({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const uploadFile = (buffer) => new Promise((resolve, reject) => { | |
| const bucketName = "YOUR-BUCKET-NAME"; | |
| const fileName = "YOUR-FILE-NAME.EXTENSION"; | |
| const data = { | |
| Bucket: bucketName, | |
| Key: fileName, | |
| Body: buffer, | |
| }; | |
| s3.putObject(data, (error) => { | |
| if (!error) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export async function main(event, context, callback) { | |
| parser(event).then(() => { | |
| uploadFile(event.body.file) | |
| .then(() => { | |
| // Handle successful upload | |
| }) | |
| .catch(() => { | |
| // Handle upload errors | |
| }); | |
| }); |
OlderNewer