🚸 #418 do not resolve write result without waiting for s3 putObject
This commit is contained in:
committed by
Anton Shepilov
parent
7ea7a302ca
commit
1ffb2eb3ea
@@ -24,19 +24,28 @@ export default class S3ConnectorService implements StorageConnectorAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
write(path: string, stream: Readable): Promise<WriteMetadata> {
|
write(path: string, stream: Readable): Promise<WriteMetadata> {
|
||||||
let totalSize = 0;
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
let totalSize = 0;
|
||||||
|
let didCompletePutObject = false;
|
||||||
|
let didCompleteCalculateSize = false;
|
||||||
|
const doResolve = () =>
|
||||||
|
didCompletePutObject &&
|
||||||
|
didCompleteCalculateSize &&
|
||||||
|
resolve({
|
||||||
|
size: totalSize,
|
||||||
|
});
|
||||||
stream
|
stream
|
||||||
.on("data", function (chunk) {
|
.on("data", function (chunk) {
|
||||||
totalSize += chunk.length;
|
totalSize += chunk.length;
|
||||||
})
|
})
|
||||||
.on("end", () => {
|
.on('end', () => { // TODO: this could be bad practice as it puts the stream in flow mode before putObject gets to it
|
||||||
resolve({
|
didCompleteCalculateSize = true;
|
||||||
size: totalSize,
|
doResolve();
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
this.client.putObject(this.minioConfiguration.bucket, path, stream).then(_x => {
|
||||||
this.client.putObject(this.minioConfiguration.bucket, path, stream).catch(e => reject(e));
|
didCompletePutObject = true;
|
||||||
|
doResolve();
|
||||||
|
}).catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user