I am working on a whatsapp bot with chatgpt like features like image generation, variation. For now when someone sends an image in the test group chat, the image is saved in the local folder.
const saveToDir = async (bufferString) => {
const bufferImage = Buffer.from(bufferString, "base64");
fs.writeFile("sampleImage.png", bufferImage, (err) => {
if (err) {
console.log("Error saving image: ", err);
} else {
console.log("Image saved successfully");
}
});
};
When I use sampleImage.png to generate variations, I get the following error. Code:
const GPTImageVariations = async () => {
try {
const response = await openai.createImageVariation(
fs.createReadStream("sampleImage.png"),
1,
"512x512"
);
console.log(response.data.data[0].url);
} catch (error) {
if (error.response) {
console.log(error.response.status);
console.log(error.response.data);
} else {
console.log(error.message);
}
}
};
Error:
400
{
error: {
code: null,
message: 'Uploaded image must be a PNG and less than 4 MB.',
param: null,
type: 'invalid_request_error'
}
}
The uploaded image has the extension png and it's size if much less than 4MB. I checked if my key was still valid and that was causing this issue but that wasn't the case.