I am using the DALLE API to generate images, and taking that file and uploading it to spotify as a playlist cover. However I receive a 413 error when I run the following line:
sp.playlist_upload_cover_image(playlist_id=playlist_id, image_b64=image)
where 'image' is my DALLE generated image in base-64 format.
image = openai.Image.create(
prompt=string_to_upload,
n=1,
size="256x256",
response_format="b64_json"
)
image = image['data'][0]['b64_json']
Here is the error message:
requests.exceptions.HTTPError: 413 Client Error: Request Entity Too Large for url: https://api.spotify.com/v1/playlists/68jf42L1vcopcrBPZkmmre/images
I believe that the b64 file that I receive from the DALLE API is slighty larger than the max file size for the spotipy upload (256 KB). I can tell because if I download the image as a png and convert it to b64 online, it says the file is about 262 KB. Is there any way I can make the b64 file from DALLE slightly smaller?
Off course there is a way to make the b64 from DALLE smaller by compressing it. You can try the PIL library with Python. CHeck the following example where we can use the PIL library for resizing and compressing it before converting it to base64.