Search code examples
phplaravellaravel-nova

Turn a files content into an UploadedFile


I have a file saved in my application whose content I would like to create a laravel UploadedFile with.

 $content = file_get_contents(storage_path('app/Imports/example.csv'));

 // returns Illuminate\Http\UploadedFile;
 $uploadedFile = $this->someMethodToMakeLaravelUploadedFile($content);

How can I achieve this?


Solution

  • You can make a new Uploadedfile

    use Illuminate\Http\UploadedFile;
    
    return new UploadedFile($path, $name);
    

    In your case

    $uploadedFile = new UploadedFile(storage_path('app/Imports/example.csv')), 'example.csv')