Error when trying to download a image using Dall-e API

After sending the prompt I received the url such:

https://oaidalleapiprodscus.blob.core.windows.net/private/org-L8JhwWATl6gmPTzpxYsazwu0/user-D84dHpIp0A4CKGYKe3fzF72s/img-aQWh7uruxBWpWs65gKl43uKZ.png?st=2022-12-04T22%3A33%3A58Z&se=2022-12-05T00%3A33%3A58Z&sp=r&sv=2021-08-06&sr=b&rscd=inlin

I sanitize it and try to download, error. Put this in the browser and receive a message that public access denied, of course. (PublicAccessNotPermittedPublic access is not permitted on this storage account. RequestId:77806e57-601e-0049-043d-087542000000 Time:2022-12-05T00:07:34.2968187Z )

Well, what should I do from here? The process to generate the image is one, but to recover the image should be other, the only thing I have is the URL, how could I keep into that session to download the image? Any idea?

2 Likes

Same error, I cannot access to my Image

Well, I quit using the URL and now I am using binary json to receive the images. Iā€™ll suggest you doing the same.

1 Like

The image URL only lasts about an hour or so. Itā€™s not meant for you to store them there long term.

Hope this helps!

1 Like

Hey Paul, I know, but when I was still trying use the URL it was a kind of instant, after receive the URL is was already invalid. I am not expecting to store, but to download. So I move to use binary json and it works fine, though I had to convert it to a valid image.

Oops. Sorry. Good to hear.

Hi Magno,

I am getting the same error when I try to download the image using the url that is returned in the initial HTTP request to generate the image.

Can you tell me how you are doing the request/conversion with binary json to get around this?

Kinds regards

Well, I was unable to download the image created at the server-side, up today! So I move to download it as the binary json. Request is the same, setting ā€˜response_formatā€™ as ā€˜b64_jsonā€™.

Depending on the language you are working it will be very different ways to convert from to a png bitmap image.

I am working in Swift version for Mac OS but I already have one done with Delphi to run my Android app, which nowadays using Delphi seems like not so common. For the sake of understanding my lib wrapper does such simple way to retrieve the files:

function TImages.DecodeJsonToFile(const Path: String): TArray<String>;
var
	i: integer;
	DecodedImage: TDecodedImage;
	ListDecodedImage: TArray<TDecodedImage>;
begin
	ListDecodedImage := ExtractImageMeta();
	SetLength(Result, Length(ListDecodedImage));
	i := 0;
	for DecodedImage in ListDecodedImage do
	begin
		Result[i] := Path + DecodedImage.FileName;
		DecodeToFile(DecodedImage.B64Json, Path + DecodedImage.FileName);
        inc(i);
	end;
end;
  1. The ExtractImageMeta() function will get the name of files into an array, as you could had request more than 1 image to be generated.
  2. We loop the image array and decode file, storing the image in a path
  3. The function returns a full path name of all the images which were downloaded and decoded

As I stated the way to decode will be depended in which language you are using, but surely today maybe all the languages can easily decode 64 bit string into binary.

1 Like

Excellent thanks Magnoā€¦ you have just unblocked me.

Going by the API documentation I thoughts I needed to chain a request to generate the image then follow up with another request to download the file. By setting the requested response to base 64, I got the actual image in the response and I could just decode the file from the payload and save it as a file on my server.

In case it helps anyone else the request from my Elixer app now looks like this:
body = Poison.encode!(%{
ā€œpromptā€: post_params[ā€œbodyā€],
ā€œnā€: 1,
ā€œsizeā€: ā€œ1024x1024ā€,
ā€œresponse_formatā€: ā€œb64_jsonā€
})
headers = [{ā€œacceptā€, ā€œapplication/jsonā€},{ā€œAuthorizationā€, ā€œBearer #{System.get_env(ā€œAPI_KEYā€)}ā€},{ā€œContent-typeā€, ā€œapplication/jsonā€}]

ase HTTPoison.post(url, body, headers, [timeout: 50_000, recv_timeout: 50_000])

ā€¦

And the response from the request is like this:

{ ā€œcreatedā€ : ā€œā€, ā€œdataā€: [{ ā€œb64_jsonā€: "asflknewlfadsknflknewlksandfā€¦

Then saving it was easy:

    data = Enum.at(response["data"], 0)
    random_string = Enum.random(1000..100000)
    File.write!("#{System.get_env("IMAGE_STORE")}/{random_string}.png", Base.decode64!(data["b64_json"]))

Thanks again Magno for taking the time to help me here. I dont think I would have figured it out on my own cause it wasnt clear from the documentation I was looking at here:

Its actually much better solution than what I was attempting anywayā€¦ still dont know why my original approach was working from localhost and not from my server.

Thank again

2 Likes

Error while download the images using Dall-E- API
hi everyone , i am trying to download using base64url, but its not getting download
can someone suggest me for the same ? i am building my app in React JS