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?
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.
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;
The ExtractImageMeta() function will get the name of files into an array, as you could had request more than 1 image to be generated.
We loop the image array and decode file, storing the image in a path
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.
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])
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.
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