I am having an issue with creating thumnail images with file already stored in the disk
Closed this issue · 2 comments
I am trying to create thumbnail image with the Laravel file storage system , but it does not work with the file already store on the disk let say public or s3 i get the following error
Exception: Unable to probe http://anotaistore.dev/storage/video/TbLAgDTXT1EDCiANartUe5gdTo76gRqn1CoTb7PC.mp4
the code is
public function store(Request $request, Video $video)
{
//Authorize the valide user
$this->authorize('upload', Video::class);
// Validate the request
$data = request()->validate([
'video' => 'required|mimeTypes:video/mp4|max:204800',
'title' => 'required',
'description' => 'required',
]);
//
$file = request()->file('video');
// Store the file to the disk
$storedFile = $file->store('video', 'public');
// set storage path to store the file (actual video)
$storage = Storage::disk('public');
$path = $storage->url($storedFile);
$thumbnail_image = $file->hashName() . ".jpg";
$thumbnail_path = 'tempo';
// This file is in project folder named tempo
$file_in_project_folder = 'tempo/Alhimyri.mp4';
Thumbnail::getThumbnail($path, $thumbnail_path, $thumbnail_image);
// Append the url to data to be stored
$dataToRecord = [
'title' => $data['title'],
'description' => $data['description'],
'url' => $path,
];
auth()->user()->createVideo($dataToRecord);
return response(['Okay', 200]);
}
Please help what prevent generation thumnail from the disk,
But when i use the $file_in_project_folder = 'tempo/Alhimyri.mp4'; instead of $path on
Thumbnail::getThumbnail($path, $thumbnail_path, $thumbnail_image);
as
Thumbnail::getThumbnail($file_in_project_folder, $thumbnail_path, $thumbnail_image);
everthing work perfectly what is the issue here
- It was due to file path and you are passing file resource url (
domain.com/public/tempo/Alhimyri.mp4
) not the file storage path(/public/tempo/Alhimyri.mp4
) - Try this
$path = storage_path('public/' . $storedFile)
- Similar issue at source
- Why use storage_path() ?
Can we do it for image stored in s3?