PenkethBoy 1942 Posted January 31, 2019 Share Posted January 31, 2019 Just trying to Upload an image via the API - and using Swagger to test but as you see below it fails 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!" } 1 Link to post Share on other sites
Luke 25828 Posted January 31, 2019 Share Posted January 31, 2019 Thanks for the info. Link to post Share on other sites
junerain 0 Posted November 20, 2019 Share Posted November 20, 2019 Hello!I want to use python to call "imageservice" to upload the actor's Avatar. Can you help me? Link to post Share on other sites
PenkethBoy 1942 Posted November 20, 2019 Author Share Posted November 20, 2019 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
junerain 0 Posted November 20, 2019 Share Posted November 20, 2019 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
PenkethBoy 1942 Posted November 20, 2019 Author Share Posted November 20, 2019 Good, glad you got it sorted Hopefully @@Luke will fix this at some point its only been 10 months or so! Link to post Share on other sites
Luke 25828 Posted November 20, 2019 Share Posted November 20, 2019 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 1942 Posted November 20, 2019 Author Share Posted November 20, 2019 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
Luke 25828 Posted November 20, 2019 Share Posted November 20, 2019 I'll add a comment about that, which swagger will display. Link to post Share on other sites
PenkethBoy 1942 Posted November 20, 2019 Author Share Posted November 20, 2019 Thanks Link to post Share on other sites
roblav96 1 Posted November 22, 2019 Share Posted November 22, 2019 @@junerain the `Content-Type` header must also be `application/octet-stream`, not `image/jpeg`. Link to post Share on other sites
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now