I have the following Laravel process happening in a job:
- If the project is using S3 disk, the file is downloaded from S3 to local disk at
storage/app/videos-to-convert/{video-name} - Use
ffmpegto copy the video and add the necessary metadata - Check some information on the metadata of the video and save to DB
- If S3 is in use, move the local file to S3.
The issue is that Laravel’s Storage::disk('local')->exists($videoPath) is returning false while file_exists($videoPath) is returning true.
// We will need to move the S3 file into local disk so that we can run FFMPEG
if ($this->isUsingS3Bucket()) {
$s3File = Storage::disk('s3')->get("videos-to-convert/{$this->session->id}.{$this->session->video_extension}");
Storage::disk('local')->put("videos-to-convert/{$this->session->id}.{$this->session->video_extension}", $s3File);
}
// Over here, we are sure of these paths.
// I have double-checked them, and they are correct.
$inputPath = storage_path("app/videos-to-convert/{$this->session->id}.{$this->session->video_extension}");
$outputPath = storage_path("app/videos/{$this->session->id}.{$this->session->video_extension}");
// The video's headless information is sent by MediaRecorder in the browser.
// We need to copy the video with ffmpeg, so we can get meta information such as the duration of the video.
shell_exec("ffmpeg -y -i $inputPath -vcodec copy -acodec copy $outputPath");
$ffprobe = FFProbe::create();
$durationInSeconds = $ffprobe->format($outputPath)->get('duration');
echo "-------\n";
$o = shell_exec("ls -la /var/www/html/storage/app/videos");
// This `ls -la` shows that the video exists in the location used in Storage::disk('local')->exists($outputPath)
echo $o;
if ($this->isUsingS3Bucket()) {
$exists = file_exists($outputPath);
$existLaravel = Storage::disk('local')->exists($outputPath);
if ($exists) {
echo "FILE EXISTS 'file_exists'------\n";
}
if ($existLaravel) {
echo "FILE EXISTS WITH Storage::disk('local') LARAVEL-----\n";
}
// The rest of the code
}
The file_exists($outputPath) returns true, but Laravel’s Storage::disk('local')->exists($outputPath) returns false. Why is this happening?
>Solution :
Because the output path should be relative to the storage,
so relative to :
storage/app
or
storage/app/public
depending on your case.
Right now laravel is searching for a file in storage/app/app/videos/* and does not find it