Wait for the image to finish writing before resizing

This commit is contained in:
Jonathan Cremin 2016-08-07 20:10:04 +01:00
parent 305dd77f43
commit 2c577cb7ae
2 changed files with 36 additions and 30 deletions

View file

@ -19,7 +19,7 @@ export function* post(next) {
uploader.acceptedEvent();
uploader.receive();
yield uploader.receive();
yield uploader.promise;

View file

@ -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() {