Last active
August 21, 2023 11:59
-
-
Save yungwarlock/8cff862c64eae1810fa669f1403f2070 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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