farshadf's avatar

reading video from sftp server gives decoded video as result

i have 4 servers which for one i use as cdn and i upload files there , for image i use the code below to retrieve images :

      if (strpos($size, 'x')) {
            [$width, $height] = explode('x', $size);
        }
        try {
            $img = Image::cache(function ($image) use ($name) {
                $fileData  = FileStorage::where('path', $name)->first();
                $directory = $this->getDirectoryPathById($fileData->directory_id, false);
                $path      = Storage::get('/public/' . $directory . '/' . $fileData->path);
                $image->make($path);
            }, 60, true);
        } catch (\Exception $e) {
            abort(404);
        }
 return Response::make($img->encode('jpg', 80), 200, ['Content-Type' => 'image/jpg'])
                       ->setMaxAge(604800)
                       ->setPublic()
            ;

now i want to add the video to that and every thing is just fine i upload the video but when i get the video in the browser is shows as a very very long string and chars now i think there should be and must be a way to encode that video and play it instead of showing as a long string of files now i return videos like below :

public function withoutAction($name)
    {
        $fileData  = FileStorage::where('path', $name)->first();
        $directory = $this->getDirectoryPathById($fileData->directory_id, false);
        $path      = Storage::disk('sftp')->get('/home/files/public/' . $directory . '/' . $fileData->path);
        //($path);
        $response = Response::make($path, 200);
        $response->header("Content-Type", 'video/mp4');
        return $response;
    }

and here is how i configued my driver :

  'sftp' => [
            'driver'     => 'sftp',
            'host'       => env('SFTP_HOST', 'someip'),
            'port'       => env('SFTP_PORT', '22'),
            'username'   => env('SFTP_USERNAME', 'username'),
            'password'   => env('SFTP_PASSWORD', 'password'),
            'privateKey' => env('SFTP_PRIVATE_KEY_PATH', ''),
            'root'       => env('SFTP_ROOT', ''),
            'timeout'    => env('SFTP_TIMEOUT', '10'),
        ],

now i recive the file but as a long string for video . should i encode that like i do with image ??

0 likes
1 reply
Amaury's avatar

Maybe by adding this header:

$response->header('Content-Disposition' => 'inline');

Please or to participate in this conversation.