refactored upload away from multipart forms to binary data
This commit is contained in:
parent
196d4211b6
commit
af7a262ef0
9 changed files with 56 additions and 93 deletions
|
@ -18,25 +18,14 @@ class S3Storage {
|
|||
return s3.getObject({ Bucket: this.bucket, Key: id }).createReadStream();
|
||||
}
|
||||
|
||||
async set(id, file) {
|
||||
let hitLimit = false;
|
||||
set(id, file) {
|
||||
const upload = s3.upload({
|
||||
Bucket: this.bucket,
|
||||
Key: id,
|
||||
Body: file
|
||||
});
|
||||
file.on('limit', () => {
|
||||
hitLimit = true;
|
||||
upload.abort();
|
||||
});
|
||||
try {
|
||||
await upload.promise();
|
||||
} catch (e) {
|
||||
if (hitLimit) {
|
||||
throw new Error('limit');
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
file.on('error', () => upload.abort());
|
||||
return upload.promise();
|
||||
}
|
||||
|
||||
del(id) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue