@pushpak1300 landed two back-to-back fixes in laravel/ai that together clean up how file overrides are handled when uploading files through Files::put.
The first PR fixes a real behavioral problem: Files::put accepted mimeType and name as override parameters, forwarded them to putFile(), and then quietly did nothing with them. Gateways kept reading the original values straight from the file itself.
The root cause was twofold. A WithMimeType decorator was never applied when a mimeType was provided, and the return value of as() was never reassigned, so immutable StorableFile implementations never picked up the rename either.
The fix in this commit wraps the file in a WithMimeType decorator when a mimeType is passed and captures the return value of as():
1// Before: overrides forwarded but never applied2$file = Files::put($path, $contents, mimeType: 'application/pdf', name: 'report.pdf');3// Gateway still read original mimeType and filename from $contents4 5// After: overrides are actually applied to the StorableFile6$file = Files::put($path, $contents, mimeType: 'application/pdf', name: 'report.pdf');7// Gateway now receives mimeType: 'application/pdf', name: 'report.pdf'
The WithMimeType decorator requires no changes to existing or third-party StorableFile implementations, so nothing downstream breaks.
Once the decorator was being applied correctly in Files::put, a separate wrapper layer that previously handled MIME type overrides for file operations became redundant. The second commit removes it entirely, cutting 185 lines across 19 files while keeping 23 lines of the logic that still matters.
This is the right order of operations: fix the behavior first, then remove the abstraction that was compensating for broken behavior. The result is a simpler code path with no hidden layers doing partial work.
If your application uploads files through Files::put and relies on overriding MIME types or filenames at that call site, the behavior before these fixes meant those overrides were silently dropped. Pulling the latest laravel/ai is the fix.
If you enjoyed this article, please consider supporting our work for as low as $5 / month.
Sponsor
Written by
Writing and maintaining @LaravelMagazine. Host of "The Laravel Magazine Podcast". Pronouns: vi/vim.
Get latest news, tutorials, community articles and podcast episodes delivered to your inbox.