Wait for the image to finish writing before resizing
This commit is contained in:
parent
305dd77f43
commit
2c577cb7ae
2 changed files with 36 additions and 30 deletions
|
@ -19,7 +19,7 @@ export function* post(next) {
|
|||
|
||||
uploader.acceptedEvent();
|
||||
|
||||
uploader.receive();
|
||||
yield uploader.receive();
|
||||
|
||||
yield uploader.promise;
|
||||
|
||||
|
|
|
@ -70,16 +70,21 @@ export default class Uploader {
|
|||
}
|
||||
|
||||
receive() {
|
||||
return new Promise((resolve) => {
|
||||
this.path = join(this.file.id[0], `${this.file.id}_${this.file.name}`);
|
||||
this.localStream = fs.createWriteStream(join(storePath, this.path));
|
||||
|
||||
this.upload.pause();
|
||||
|
||||
this.localStream.on('finish', () => {
|
||||
resolve();
|
||||
});
|
||||
|
||||
this.upload.on('data', (data) => {
|
||||
this.receivedSize += data.length;
|
||||
if (this.receivedSize > this.context.user.max_filesize) {
|
||||
fs.unlink(join(storePath, this.path));
|
||||
this.context.throw(413, `{"error": {"message": "The file you tried to upload is too large.",
|
||||
this.context.throw(413, `{"error": {"message": "The file you uploaded is too large.",
|
||||
"code": 601}}`);
|
||||
}
|
||||
|
||||
|
@ -105,6 +110,7 @@ export default class Uploader {
|
|||
});
|
||||
|
||||
this.upload.resume();
|
||||
});
|
||||
}
|
||||
|
||||
acceptedEvent() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue