I store an object to Cloud Storage like this:
<code>const bucket = getStorage().bucket();
const fileRef = bucket.file("/foo/bar");
const storageWriteStream = fileRef.createWriteStream();
const myFileStream = someLibraryThatCreatesAStream();
storageWriteStream.on("error", (err) => {
functions.logger.error(err);
});
storageWriteStream.on("close", (err) => {
return await getDownloadURL(fileRef)
});
myFileStream.pipe(storageWriteStream);
</code>
<code>const bucket = getStorage().bucket();
const fileRef = bucket.file("/foo/bar");
const storageWriteStream = fileRef.createWriteStream();
const myFileStream = someLibraryThatCreatesAStream();
storageWriteStream.on("error", (err) => {
functions.logger.error(err);
});
storageWriteStream.on("close", (err) => {
return await getDownloadURL(fileRef)
});
myFileStream.pipe(storageWriteStream);
</code>
const bucket = getStorage().bucket();
const fileRef = bucket.file("/foo/bar");
const storageWriteStream = fileRef.createWriteStream();
const myFileStream = someLibraryThatCreatesAStream();
storageWriteStream.on("error", (err) => {
functions.logger.error(err);
});
storageWriteStream.on("close", (err) => {
return await getDownloadURL(fileRef)
});
myFileStream.pipe(storageWriteStream);
But when called on the front-end, the result is always null
. Since Functions seems to always has trouble with return
as part of an event handler, I think it’s because Functions doesn’t wait for storageWriteStream
‘s close
event.
How do I get around this?