Created
September 10, 2022 23:47
-
-
Save sunnyy02/a4c1418c62ccdbc658757d3f7863a5e7 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
@Injectable() | |
export class FileService { | |
async uploadPublicFile(dataBuffer: Buffer, filename: string) { | |
try { | |
const s3 = new S3(); | |
const uploadResult = await s3 | |
.upload({ | |
Bucket: 'file-uploads', | |
Body: dataBuffer, | |
Key: `${uuid()}-${filename}` | |
}) | |
.promise(); | |
return { | |
key: uploadResult.Key, | |
url: uploadResult.Location, | |
}; | |
} catch (err) { | |
console.log(err); | |
return { key: 'error', url: err.message }; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment