Skip to content

Commit a7ba325

Browse files
authored
Merge pull request #3477 from codeeu/week_10_feb
qc edits
2 parents 7cbc1fd + 0c54699 commit a7ba325

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

app/Nova/Actions/BulkUploadMediaFiles.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Queue\InteractsWithQueue;
1111
use Illuminate\Queue\SerializesModels;
1212
use Illuminate\Support\Collection;
13+
use Illuminate\Support\Facades\Log;
1314
use Illuminate\Support\Facades\Storage;
1415
use Illuminate\Support\Str;
1516
use Laravel\Nova\Actions\Action;
@@ -185,15 +186,28 @@ protected function storeFile(UploadedFile|string $file, string $destination, str
185186
return null;
186187
}
187188

189+
$targetPath = $destination . '/' . $finalFileName;
188190
$stream = Storage::disk($data->disk)->readStream($data->path);
189-
if ($stream === false) {
190-
return null;
191-
}
192191

193-
$targetPath = $destination . '/' . $finalFileName;
194-
$stored = Storage::disk('resources')->put($targetPath, $stream, 'public');
195192
if (is_resource($stream)) {
196-
fclose($stream);
193+
try {
194+
$stored = Storage::disk('resources')->writeStream($targetPath, $stream, ['visibility' => 'public']);
195+
} finally {
196+
fclose($stream);
197+
}
198+
} else {
199+
// Some environments return null instead of a stream for temp files.
200+
// Fallback to reading file contents directly.
201+
$contents = Storage::disk($data->disk)->get($data->path);
202+
if (!is_string($contents) || $contents === '') {
203+
Log::warning('[BulkUploadMediaFiles] Unable to read temp file contents', [
204+
'disk' => $data->disk,
205+
'path' => $data->path,
206+
]);
207+
return null;
208+
}
209+
210+
$stored = Storage::disk('resources')->put($targetPath, $contents, 'public');
197211
}
198212

199213
// Clean temporary Filepond directory.

0 commit comments

Comments
 (0)