microsoftgraph / microsoftgraph/msgraph-sdk-php

v2 plain text attachment arrives unreadable

Offen
#1,458 0 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@SilasKenneth arbeitet bereits daran.

Seit 21.2.2024.

area: outlook bug
Vorherrschende Sprache
PHP
Sterne
669
Forks
150
Ø Merge
15 Std. 21 Min.
Gemergte PRs (30 T.)
3

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.