Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

how to upload and set avatar for user

yunwu
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 28, 2022 edited

I am using version 9.0 of JIRA. I want to upload pictures as user avatars using the rest API, but I have encountered some problems when program in nodejs。

1. according to the URL, the binary data of the picture is obtained from other places,

2. via /reset/api/2/

` http://IP:PORT/rest/api/latest/user/avatar/temporary?username=SomeOneUserName&filename=icon.png ` to upload the picture as temporary

3. create avatar according to temporary

4. set the user's Avatar as this Avatar

the step 3 is failed. and response status code is 500, but i cannot get detail info.

The code is as follows, 


// step 1
const res = await axios.get(AvatarImageUrl, {
        responseType: 'arraybuffer',
});
let ImageData = res.data;
// step 2
let Resp = await axios
  (
    {
      method: 'post',
      data: ImageData,
      headers:
      {
        "Authorization": `Bearer ${token}`,
        "Content-Type": "image/png",
        "Content-Length": ImageData.length,
        "X-Atlassian-Token": "no-check",
      },
    }
  );
  let CropData = Resp.data;
// step 3
let Resp2 = await axios
(
    {
      method: 'post',
      data: CropData,
      headers:
      {
        'Content-Type': "application/json",
        "Authorization": `Bearer ${token}`,
        "X-Atlassian-Token": "no-check",
        'Cookie': `${CookieId}`,
      },
    }
  );
  context.log("resp2", Resp2);

1 answer

0 votes
yunwu
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 28, 2022 edited

I have solved it,

1. step 1 download 48x48 size pictures directly

2. skip step 3, when uploading to the temporary with 48x48 size image,  its reponse directly contains the avatar id. You can directly set the user's Avatar without going through the crop

Suggest an answer

Log in or Sign up to answer