Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel's Storage::exists returns false while file_exists return true

I have the following Laravel process happening in a job:

  1. If the project is using S3 disk, the file is downloaded from S3 to local disk at storage/app/videos-to-convert/{video-name}
  2. Use ffmpeg to copy the video and add the necessary metadata
  3. Check some information on the metadata of the video and save to DB
  4. 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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading