Created
February 13, 2020 16:49
-
-
Save stemmlerjs/97933def5ccf8278603e036dcf4b06fc to your computer and use it in GitHub Desktop.
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 class AWSS3Uploader implements IUploader { | |
| private s3: AWS.S3; | |
| public config: S3UploadConfig; | |
| ... | |
| private createDestinationFilePath( | |
| fileName: string, | |
| mimetype: string, | |
| encoding: string | |
| ): string { | |
| return fileName; | |
| } | |
| async singleFileUploadResolver( | |
| parent, | |
| { file }: { file: Promise<ApolloServerFileUploads.File> } | |
| ): Promise<ApolloServerFileUploads.UploadedFileResponse> { | |
| const { stream, filename, mimetype, encoding } = await file; | |
| // Create the destination file path | |
| const filePath = this.createDestinationFilePath( | |
| filename, | |
| mimetype, | |
| encoding | |
| ); | |
| // Create an upload stream that goes to S3 | |
| // Pipe the file data into the upload stream | |
| // Get the link representing the uploaded file | |
| // (optional) save it to our database | |
| return { filename, mimetype, encoding, url: '' }; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment