validate([ 'filename' => ['required', 'string', 'max:255'], 'mime_type' => ['required', 'string', 'max:100'], ]); $extension = pathinfo($validated['filename'], PATHINFO_EXTENSION) ?: 'bin'; $key = 'temp/'.Str::uuid().'.'.$extension; $s3 = new S3Client([ 'region' => config('filesystems.disks.s3.region'), 'endpoint' => config('filesystems.disks.s3.endpoint'), 'use_path_style_endpoint' => config('filesystems.disks.s3.use_path_style_endpoint'), 'credentials' => [ 'key' => config('filesystems.disks.s3.key'), 'secret' => config('filesystems.disks.s3.secret'), ], ]); $command = $s3->getCommand('PutObject', [ 'Bucket' => config('filesystems.disks.s3.bucket'), 'Key' => $key, 'ContentType' => $validated['mime_type'], ]); $presignedUrl = (string) $s3->createPresignedRequest($command, '+15 minutes')->getUri(); return response()->json([ 'key' => $key, 'url' => $presignedUrl, 'expires_at' => now()->addMinutes(15)->toISOString(), ]); } }