Jump to content

Uploading and Image via API - Swagger Error


PenkethBoy

Recommended Posts

PenkethBoy

Just trying to Upload an image via the API - and using Swagger to test

 

but as you see below it fails

 

5c52ea0ea4b7c_Capture1.jpg

 

The response body error (from a bit of google foo) - indicates the uploaded file is not being encoded to base64 in swagger

 

And also the Content-Type should be "image/jpeg"

 

Not a major problem - but worth fixing I think

 

For those who may come across this at a later date

 

a small snippet of Powershell code that works for uploading a Primary image file via the API

# $embyImage.ID is the Emby ID of the item you wish to change the primary image of
$ImageUrl = $embyServerUrl + "/emby/Items/"+ $EmbyImage.ID + "/Images/Primary?api_key=" + $User.AccessToken

# Encode jpg to a base64 string - $BackImage.Fullname is the full path to the jpg file
[String]$Base64 = [convert]::ToBase64String((Get-Content $BackImage.FullName -Encoding Byte))

$Result = Invoke-Webrequest -uri $ImageUrl -Method POST -Body $Base64 -ContentType "image/jpeg"

If ($Result.StatusCode -eq 204)
{
     Write-Host "Success!!!!"
}
else
{
     Write-Host "Boo Fail!"
}
  • Like 1
Link to post
Share on other sites
  • 9 months later...
PenkethBoy

Now you have the URL correct :) - you need to encode the image to base64 as i described above as you are getting the same error i was

 

how you do that in python i do not know - sorry

Link to post
Share on other sites

 5dd5719440a88_5.png

 

I succeeded. requests.post(data=)can upload binary Base64.

I didn't know how to give the base64 body to the API In which form before.

 

Thank you. I tried your PowerShell code, so I'm confident to finish it by python.

Link to post
Share on other sites

Fix for what? It has to be base64 encoded and I don't think the swagger UI supports doing that, so you won't be able to test the endpoint from there.

Link to post
Share on other sites
PenkethBoy

If swagger does not support it then what use is there in having the swagger option

 

Maybe have a note as a minimum to tell api users that they need to encode the image

 

As the api calls as listed curl or http - give no clue this is whats needed - hence the original post

Link to post
Share on other sites

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...