Jump to content

Collections images by API


Recommended Posts

Posted

Dear all,

I've created collections with the API and they are displayed without any images.

I tried several solution to add them with the API without any succes, i still have 400 error like this :

[DEBUG] tmp_path = /tmp/tmp9lyc1b03.jpg [DEBUG] taille du fichier = 186243 bytes

[ERREUR] Upload Primary échoué pour 20439: 400 Client Error: Bad Request for url: http://localhost:8096/Items/20439/Images/Primary?api_key=axxxxxxxxxxxxxxa [

If you know the solution to add 'Primary', 'Backdrop', and 'Logo' images by this way (a new scan of the collections do not add any images) ?

Many thanks !

Posted

More details of the request (return error 400):

    url = f"{emby_url}/Items/{collection_id}/Images/{image_type}?api_key={api_key}"
    
    try:
        with open(local_file, "rb") as f:
            files = {"file": (os.path.basename(local_file), f, "image/jpeg")}
            resp = requests.post(url, files=files)
            resp.raise_for_status()

 

Posted

Dear, thanks for your answser, 

  • I've tested on multipart/form-data (-F), answer 400.

  • I've tested on  --data-binary avec Content-Type: image/jpeg, même résultat.

  • Sample with curl :

curl -v \ -H "Content-Type: image/jpeg" \ --data-binary @/tmp/test.jpg \ "http://localhost:8096/Items/20439/Images/Primary?api_key=XXXXX" 

et Emby answer :

HTTP/1.1 400 Bad Request Unable to determine image file extension from mime type multipart/form-data

or

Requested value 'jpg' was not found.

thanks a lot for your help,

regards.

 

Posted

HI, did you try comparing to what the web app is sending? You can use the browser debugger to monitor that.

Posted

Hi, web app doesn't work for me (?), so i can't test with it.

Could you please confirm if what is the right curl request to add images on a collection?

Many thanks,

Regards.

Posted
3 minutes ago, ericm69 said:

Hi, web app doesn't work for me (?), so i can't test with it.

Could you please confirm if what is the right curl request to add images on a collection?

Many thanks,

Regards.

Hi, what do you mean by doesn’t work for you?

Posted

The soluce  : A bit strange, convert to 64b image but content type jpg.

with open("/tmp/thumb.jpg", "rb") as f:
    img_data = f.read()

img_b64 = base64.b64encode(img_data)

url = f"{server_url}Items/{item_id}/Images/Thumb?api_key={api_key}"
headers = {"Content-Type": "image/jpeg", "X-Emby-Token": api_key}

resp = requests.post(url, headers=headers, data=img_b64)
print(resp.status_code, resp.text)

 

  • Thanks 1
Posted
6 hours ago, ericm69 said:

The soluce  : A bit strange, convert to 64b image but content type jpg.

with open("/tmp/thumb.jpg", "rb") as f:
    img_data = f.read()

img_b64 = base64.b64encode(img_data)

url = f"{server_url}Items/{item_id}/Images/Thumb?api_key={api_key}"
headers = {"Content-Type": "image/jpeg", "X-Emby-Token": api_key}

resp = requests.post(url, headers=headers, data=img_b64)
print(resp.status_code, resp.text)

 

Hi, yes it's old. We probably need a new upload api at this point. Thanks.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...