Skip to content

Instantly share code, notes, and snippets.

@sunnyy02
Created September 10, 2022 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunnyy02/a4c1418c62ccdbc658757d3f7863a5e7 to your computer and use it in GitHub Desktop.
Save sunnyy02/a4c1418c62ccdbc658757d3f7863a5e7 to your computer and use it in GitHub Desktop.
@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