Hello. I’m building a backend for our web app that uses createImageEdit api. Ideally I would like to have users provide images to our backend in either Buffer or B64 format, then we pass it off to openai for processing. However I’m running into some issues while trying to use createImageEdit API.
When testing with local images, I can’t seem to be able to get Buffer or B64 format to work. The API keeps returning 400.
const imagePath = path.join(__dirname, "../tests/corgi-dog.png")
const imageData = fs.readFileSync(imagePath,)
const maskPath = path.join(__dirname, "../tests/corgi-mask.png")
const maskData = fs.readFileSync(maskPath)
return openai.createImageEdit(imageData, prompt, maskData, 4)
fails
const imagePath = path.join(__dirname, "../tests/corgi-dog.png")
const imageData = fs.readFileSync(imagePath, "base64")
const maskPath = path.join(__dirname, "../tests/corgi-mask.png")
const maskData = fs.readFileSync(maskPath, "base64")
return openai.createImageEdit(imageData, prompt, maskData, 4)
fails as well
I was only able to get it to work when passing in streams to the API like so:
const imagePath = path.join(__dirname, "../tests/corgi-dog.png")
const imageData = fs.createReadStream(imagePath)
const maskPath = path.join(__dirname, "../tests/corgi-mask.png")
const maskData = fs.createReadStream(maskPath)
return openai.createImageEdit(imageData, prompt, maskData, 4)
Does anyone know if createImageEdit API can work with Buffer or B64 strings? Some forum posts seem to suggest it’s supported but I just can’t get it to work.
our stopgap solution currently is to write the Buffer to disc then read it to a stream.
function hackyStuff(buffer: Buffer, path: string) {
fs.writeFileSync(path, buffer)
return fs.createReadStream(path)
}
But that’s far from ideal. If anyone has gotten any format other than stream to work with the createImageEdit API and can share the solution that will be greatly appreciated.