Skip to content

Commit 5f80a50

Browse files
authored
Merge pull request #3480 from codeeu/week_10_feb
Week 10 feb
2 parents 61ce282 + febaf15 commit 5f80a50

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

app/Nova/Actions/BulkUploadMediaFiles.php

Lines changed: 23 additions & 8 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,19 +186,33 @@ 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

199-
// Clean temporary Filepond directory.
200-
$data->deleteDirectory();
213+
// Clean only this temp file. Deleting the whole directory can remove
214+
// sibling files from the same multi-upload batch.
215+
$data->deleteFile();
201216

202217
return $stored ? $targetPath : null;
203218
}

0 commit comments

Comments
 (0)