Skip to content

Instantly share code, notes, and snippets.

@yungwarlock
Last active August 21, 2023 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yungwarlock/8cff862c64eae1810fa669f1403f2070 to your computer and use it in GitHub Desktop.
Save yungwarlock/8cff862c64eae1810fa669f1403f2070 to your computer and use it in GitHub Desktop.
async function uploadCourseThumbnail(path: string) {
const fileID = createID();
const file = storage.file(`${fileID}.png`);
file.makePublic();
return new Promise((resolve, reject) => {
const publicUrl = file.publicUrl();
fs.createReadStream(path)
.pipe(file.createWriteStream({
metadata: {
contentType: "image/png",
}
}))
.on("error", (err) => {
reject(err);
})
.on("close", () => {
resolve(publicUrl);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment