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

Bug: type of FileAttachment.contentBytes should be string instead of number #23

Open
abdulkareemnalband opened this issue Sep 11, 2018 · 6 comments
Assignees
Labels
ADO to GitHub automation label Issue caused by core project dependency modules or library tracked

Comments

@abdulkareemnalband
Copy link

abdulkareemnalband commented Sep 11, 2018

Bug

Type of FileAttachment.contentBytes should be string instead of number

in

contentBytes?: number

AB#7041

@muthurathinam
Copy link
Contributor

muthurathinam commented Sep 17, 2018

@abdulkareemnalband Thank you for reporting. will look into this and get back to you.
883193

@darrelmiller
Copy link

@muthurathinam This is declared as <Property Name="contentBytes" Type="Edm.Binary"/>. What do we normally use for mapping to Binary type? Can we use a byte array?

@bamncan
Copy link

bamncan commented Oct 31, 2019

Verifying that sending this property in as a base64 encoded string is what is accepted by the API.

let attachment: any = {
  '@odata.type': '#microsoft.graph.fileAttachment',
  contentBytes: Buffer.from('attachment').toString('base64'),
  contentType: 'text/plain',
  name: 'attachment.txt',
  size: 10
}

or

contentBytes: 'YXR0YWNobWVudA==',

Either will be accepted by the API when adding the attachment.

@RobvH
Copy link

RobvH commented Jul 14, 2022

This issue is still present and I've submitted a PR to correct the mistake. In the PR I link to the documentation and describe that it contains a contradiction that caused this error in the first place. In short, the type is not Edm.Binary in transmission, as the description accurately states, it is the "The base64-encoded contents of the file." Base64 encoding, by definition generates a string.

The impact of this bug is forcing test authors to cast through unknown to allow Typescript to ignore the contradiction between the incorrect type and actual API responses used as test fixtures; nullifying much of the value of the type in the first place.

Thanks for all your hard work and efforts on this and I hope this PR helps! ❤️

@RobvH
Copy link

RobvH commented Jul 14, 2022

I also raised this issue with the Docs project here: https://github.com/microsoftgraph/microsoft-graph-docs-contrib/issues/1972

@RobvH
Copy link

RobvH commented Aug 22, 2022

The fix was made upstream and the corrected types are in PR microsoftgraph/microsoft-graph-docs#328

❤️ Thanks to everyone who helped with this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ADO to GitHub automation label Issue caused by core project dependency modules or library tracked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants