microsoftgraph / microsoftgraph/msgraph-sdk-php
v2 plain text attachment arrives unreadable
Open
@SilasKenneth is already working on this.
Since Feb 21, 2024.
area: outlook
bug
- Dominant language
- PHP
- Stars
- 669
- Forks
- 150
- Avg merge
- 15h 21m
- Merged PRs (30d)
- 3
Description
Hello,
We're migrating code that was using v1 of the SDK to v2, however I'm running into an issue receiving attachments.
The test code attaches a plain text file to the message but upon receiving the email, the file is unreadable.
The exact same file works fine with v1 of the SDK.
Sample code:
$attach = [];
foreach ($attachments as $path => $mimeType) {
if (!is_readable($path))
throw new \InvalidArgumentException("$path is not readable and cannot be attached.");
$attachment = new FileAttachment();
$attachment->setOdataType('#microsoft.graph.fileAttachment');
$attachment->setName(pathinfo($path, PATHINFO_BASENAME));
$attachment->setContentType($mimeType);
/* DEBUG */
print($attachment->getContentType() . "\n"); // "text/plain"
$resource = Utils::tryFopen($path, 'r');
$attachment->setContentBytes(Utils::streamFor($resource));
echo $attachment->getContentBytes()->getContents(); // "sample used for attachments" -- as expected
$attachment->getContentBytes()->rewind(); // for debugging
$attach[] = $attachment;
}
$message->setAttachments($attach);
File that gets attached: sample_attachment.txt
Received file: test_attachment_received.txt
Everything else in the received email is as expected.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.