Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save files with storeAs outside the Storage folder

Tags:

laravel-5.5

I have in an API in Laravel that stores files

$request->file("file$i")->storeAs('categories', $nameFile)

As it stands it stores the data correctly in the address

/var/www/html/apiapp/storage/app/public/categories

But I would like to save these files in the folder

/var/archives

Because these files will be accessed by another application

like image 384
Magas Avatar asked Jan 28 '23 22:01

Magas


1 Answers

The third argument of storeAs tells on which storage disk the file should be saved

$path = $request->photo->storeAs('images', 'filename.jpg', 's3');

So, create a new disk in config/filesystem.php and point it to /var/archives

'disks' => [

    // ...

    'archive' => [
        'driver' => 'local',
        'root' => '/var/archives',
    ],

    // ...

In the code:

$request->file("file$i")->storeAs('categories', $nameFile, 'archive')

Ensure that the user running the webserver has permission to save to that folder on disk as well.

Another alternative is to share an external storage, such as AWS S3 for example. The configuration for this follows the same idea.

I received this answer on stackoverflow in Portuguese and it worked perfectly

like image 187
Magas Avatar answered Feb 05 '23 18:02

Magas