Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type for uploading a user avatar is incorrect and requires adding isForm: true to work #3611

Closed
2 tasks done
mdsummers opened this issue Jul 15, 2024 · 1 comment · Fixed by #3644
Closed
2 tasks done
Labels
released This issue/pull request has been released. type:bug Changes fix a minor bug

Comments

@mdsummers
Copy link

Description

  • Node.js version: 18.20.3
  • Gitbeaker version: @gitbeaker/[email protected]
  • Gitbeaker release (cli, rest, core, requester-utils): rest
  • OS & version: macOS 14.5

The type for the avatar field for creating / editing a user is defined as follows:

avatar?: { content: Blob; filepath?: string };

(an object with a content and filepath field). However, this does not work, a "Bad Request" is returned from gitlab. Non-working example:

await api.Users.edit(userId, {
  avatar: {
    content: new Blob([imageBuffer], { type: 'image/png' }),
    filepath: 'avatar.png'
  }
}); // throws GitbeakerRequestError: Bad request

Searching through the source code for isForm: true seems to indicate that there should be an implementation for Users.ts that takes avatar in the above form and converts it to a tuple adding isForm: true. As such the following is a workaround right now:

await api.Users.edit(userId, {
  avatar: [new Blob([imageBuffer], { type: 'image/png' }), 'avatar.png'],
  isForm: true
});

Steps to reproduce

The first snippet above shows a bit of code which reproduces

Expected behaviour

We don't get a 400 Bad Request back

Actual behaviour

We get a 400 Bad Request back.

Possible fixes

Add handling in Users.ts to take avatar in the format indicated by the type into form format.

Checklist

  • I have checked that this is not a duplicate issue.
  • I have read the documentation.
@jdalrymple
Copy link
Owner

🚀 Issue was released in 41.1.0 🚀

@jdalrymple jdalrymple added the released This issue/pull request has been released. label Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released This issue/pull request has been released. type:bug Changes fix a minor bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants