Skip to content

Fix repeated attachment content reads#167

Merged
stevebauman merged 1 commit into
masterfrom
fix-attachment-contents-stream
Jul 6, 2026
Merged

Fix repeated attachment content reads#167
stevebauman merged 1 commit into
masterfrom
fix-attachment-contents-stream

Conversation

@stevebauman

Copy link
Copy Markdown
Member

Description

Fixes #166.

Calling Attachment::contents() currently drains the underlying PSR-7 stream because getContents() reads from the stream's current cursor position to the end. If a developer reads an attachment's contents first and then calls save(), the stream cursor is already at EOF, so the saved file is created with zero bytes.

This updates Attachment::contents() to rewind seekable streams before reading, so the high-level attachment API consistently returns the full attachment contents. Developers who need raw cursor-based stream behavior can still access the stream directly through contentStream().

Tests

  • vendor/bin/pest tests/Unit/AttachmentTest.php
  • vendor/bin/pest tests/Unit

@stevebauman stevebauman merged commit 7dd94f7 into master Jul 6, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using $attachment->contents() empties the content of the attachment!

1 participant