Stream tenant uploads
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-01-02 20:51:52 +01:00
parent eed7699549
commit 3e9f09571b
5 changed files with 123 additions and 5 deletions

View File

@@ -14,6 +14,7 @@ use App\Services\Packages\PackageUsageTracker;
use App\Services\Storage\EventStorageManager;
use App\Support\ApiError;
use App\Support\ImageHelper;
use App\Support\UploadStream;
use App\Support\WatermarkConfigResolver;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -318,7 +319,7 @@ class PhotoController extends Controller
$path = "events/{$eventSlug}/photos/{$filename}";
// Store original file
Storage::disk($disk)->put($path, file_get_contents($file->getRealPath()));
UploadStream::putUploadedFile($disk, $path, $file);
// Generate thumbnail
$thumbnailPath = "events/{$eventSlug}/thumbnails/{$filename}";
@@ -354,6 +355,7 @@ class PhotoController extends Controller
$photoAttributes = [
'event_id' => $event->id,
'guest_name' => Photo::SOURCE_TENANT_ADMIN,
'original_name' => $file->getClientOriginalName(),
'mime_type' => $file->getMimeType(),
'size' => $file->getSize(),
@@ -904,7 +906,7 @@ class PhotoController extends Controller
$path = "events/{$eventSlug}/photos/{$filename}";
// Store file
Storage::disk($disk)->put($path, file_get_contents($file->getRealPath()));
UploadStream::putUploadedFile($disk, $path, $file);
// Generate thumbnail
$thumbnailPath = "events/{$eventSlug}/thumbnails/{$filename}";
@@ -915,6 +917,7 @@ class PhotoController extends Controller
$photoAttributes = [
'event_id' => $event->id,
'guest_name' => Photo::SOURCE_TENANT_ADMIN,
'original_name' => $request->original_name,
'mime_type' => $file->getMimeType(),
'size' => $file->getSize(),

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Support;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
class UploadStream
{
/**
* Store an uploaded file without loading it fully into memory.
*/
public static function putUploadedFile(string $disk, string $path, UploadedFile $file): bool
{
$sourcePath = $file->getRealPath() ?: $file->getPathname();
if (! $sourcePath) {
return false;
}
$stream = fopen($sourcePath, 'rb');
if (! $stream) {
return false;
}
try {
return Storage::disk($disk)->put($path, $stream);
} finally {
if (is_resource($stream)) {
fclose($stream);
}
}
}
}