I am struggling to retrieve an image from firebase storage and transmit it to an openai endpoint
Here is my current code snippet:
const fileStorage = await getStorageAdmin(uid, "/sample.png");
const file = fileStorage.createReadStream();
const maskStorage = await getStorageAdmin(uid, "/mask.png");
const mask = maskStorage.createReadStream();
const res = await openai.createImageEdit(
file,
prompt,
mask,
1,
"512x512",
"url"
).catch((e) => {
console.log("ERROR: " + e)
})
However, executing this code yields a Bad Request (status code: 400).
Interestingly, when I attempted to read the files from the hard disk, it worked flawlessly
const file = fs.createReadStream("./images/anna.png");
const mask = fs.createReadStream("./images/mask.png");
const res = await openai.createImageEdit(
file,
prompt,
mask,
1,
"512x512",
"url"
).catch((e) => {
console.log("ERROR: " + e)
})
This indicates that the API request is valid but there seems to be an issue with reading from firebase storage since that is the only disparity, yet I am unable to identify my mistake. I'm perplexed as to why using fs.createReadStream() and firebase-admin's file.createReadStream results in different outcomes. I assumed both methods should provide the image contents, however, one works while the other does not.
The getStorageAdmin function simply retrieves the reference to the desired file for download.
export const getStorageAdmin = async (uid:string, imagepath:string) =>{
return await getStorage().bucket().file(uid+imagepath)
}