Using Zammd API for Avatar upload

Infos:

  • Used Zammad version: 5.3.1-1677147662.62001c62.bullseye
  • Used Zammad installation type: package
  • Operating system: Debian GNU/Linux 11 (bullseye)
  • Browser + version: -

Expected behavior:

  • Successfully uploaded avatar image

Actual behavior:

  • {“error”: “The image is invalid.”}

Steps to reproduce the behavior:

  • curl https://xxx.xxx.xxx.de/api/v1/users/avatar -v -u username:pw -H “Content-Type: application/json” -X POST -d ‘{“avatar”: “data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4gKgSUNDX1BST0ZJTEUAAQEAAAKQbGNtcwQwAABtbnRyUkdCIFhZWiAH4QACAA8ABwAuAA1hY3NwQVBQTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9t…”}’

I tried several images. I even fetched one base64 encoded image from an existing avatar and used that one. But without success! The command I used is from the source code of Zammad:zammad/app/controllers/users_controller.rb:826

I tried several things in Postman (raw-data, form-data), and I dug a bit deeper and checked the image validate class (zammad/app/services/service/avatar/image_validate.rb) and even the static_asset (zammad/lib/static_assets.rb).

The image is null, or the StaticAssets.data_url_attributes(image_data) function recognizes that the base64 string is invalid. But the image I provide exists and is not too big or has an invalid mime type.

I hope someone has an idea. I am slowly getting crazy with this!

Thanks.

Ok, I found a solution by myself. The sample code is old and is not working anymore… Here is a working example of how to upload an avatar image:

curl --location --request POST 'https://FQDN_or_IP/api/v1/users/avatar' \
--header 'Content-Type: application/json; charset=utf-8' \
--header 'Authorization: Token token="xxx"' \
--data-raw '{"avatar_full": "data:image/jpeg;base64,/9j/4RM1RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAA...",
"avatar_resize": "data:image/jpeg;base64,/9j/4RM1RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAA..."}'

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.