2

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}`);
}
1
  • You are running the code on a server, right? How can there be a CORS error?
    – dshukertjr
    May 15, 2023 at 8:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.