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

Users[userId].MailFolders[mailFolderId].Messages[messageId].Attachments.ContentBytes does not appear to be base64 encoded #2836

Open
catmanjan opened this issue Feb 17, 2025 · 3 comments
Labels
area:documentation Focused on documentation of the product type:question An issue that's a question

Comments

@catmanjan
Copy link

Describe the bug

According to the summary comment ContentBytes is "The base64-encoded contents of the file."

However the bytes do not appear to be base64 encoded, because if I try to decode them I get an error that it is not base64 encoded

Expected behavior

Probably the comment needs to be verified

How to reproduce

var attachment = await graphClient.Users[userId].MailFolders[mailFolderId].Messages[messageId].Attachments[attachmentId]
.GetAsync() as FileAttachment;

var bytes = attachment.ContentBytes;
var base64Chars = Encoding.UTF8.GetChars(attachment.ContentBytes);
var decodedBytes = Convert.FromBase64CharArray(base64Chars, 0, base64Chars.Length);

Throws an error

SDK Version

No response

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_
@catmanjan catmanjan added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Feb 17, 2025
@andrueastman
Copy link
Member

Thanks for raising this @catmanjan

I believe the byte array should already be base64 decoded. Decoding the ContentBytes property would be performing a second decode which would fail.

For reference see the implementation links below.

@andrueastman andrueastman added type:question An issue that's a question status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Feb 17, 2025
@catmanjan
Copy link
Author

catmanjan commented Feb 17, 2025 via email

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Feb 17, 2025
@andrueastman
Copy link
Member

That's true. The contents do come from the API as a base64 encoded string. But the SDK changes this to a byte array.

The SDK generation process does however pull the property information from the public documentation which is the real source of the confusion here. https://learn.microsoft.com/en-us/graph/api/resources/fileattachment?view=graph-rest-1.0#properties

@andrueastman andrueastman added area:documentation Focused on documentation of the product and removed Needs: Attention 👋 labels Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:documentation Focused on documentation of the product type:question An issue that's a question
Projects
None yet
Development

No branches or pull requests

2 participants