I tried using the URL that is returned by default but there is a CORS issue on OpenAI's end which won't allow me to use fetch
. So now I am trying to use b64_json
but I cannot figure out how to get that in a format that can be uploaded. Everything I have tried throws an error. Below is the code I'm using.
const configuration = new Configuration({
apiKey: OpenAIApiKey,
});
const openai = new OpenAIApi(configuration);
const response = await openai.createImage({
prompt: prompt,
size: "512x512",
response_format: "b64_json",
});
console.log("Uploading image...");
const {
data,
error
} = await supabase.storage
.from("public/posts")
.upload(fileName, decode(response.data.data[0].b64_json), {
contentType: "image/png",
});
if (error) {
throw new Error(`Failed to upload image: ${error.message}`);
}