first
This commit is contained in:
45
app/Services/StorageService.php
Normal file
45
app/Services/StorageService.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class StorageService
|
||||
{
|
||||
private const DISK = 'private';
|
||||
|
||||
public function storeAudio(UploadedFile $file, string $uuid): string
|
||||
{
|
||||
$ext = $file->getClientOriginalExtension();
|
||||
$filename = Str::random(40) . '.' . strtolower($ext);
|
||||
$dir = "transcriptions/{$uuid}/audio";
|
||||
|
||||
Storage::disk(self::DISK)->putFileAs($dir, $file, $filename);
|
||||
|
||||
return "{$dir}/{$filename}";
|
||||
}
|
||||
|
||||
public function delete(string $path): void
|
||||
{
|
||||
if (Storage::disk(self::DISK)->exists($path)) {
|
||||
Storage::disk(self::DISK)->delete($path);
|
||||
}
|
||||
}
|
||||
|
||||
public function exists(string $path): bool
|
||||
{
|
||||
return Storage::disk(self::DISK)->exists($path);
|
||||
}
|
||||
|
||||
public function size(string $path): int
|
||||
{
|
||||
return Storage::disk(self::DISK)->size($path);
|
||||
}
|
||||
|
||||
public function readStream(string $path)
|
||||
{
|
||||
return Storage::disk(self::DISK)->readStream($path);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user