BO
466 10
Asked
Updated
Viewed
2k times

I've recently made a file manager entirely using the file facade because I initially wanted to have the disk configurable via a database rather than a config file. However, now that I’m done everything works without any configuration.

I see that Laravel not only offers a file facade, but also a storage facade. What are the differences between the two? Why should I use the file facade vs the storage facade?

Should I convert to using the storage facade? Would it provide any additional features or advantages that might desirable for my filemanager package?

  • 0
    The file manager package is published on github and on packagist so it's possible to obtain it VIA composer if you want to test it. The code is kind of ugly and there is no validation when uploading at the moment as it's still a work in progress. I guess converting it to use the storage facade opens up the possibility of integrating AWS into it. — Bogey
add a comment
0

1 Answer

  • Votes
  • Oldest
  • Latest
Answered
Updated

The File facade is essentially a wrapper around PHP that offers just basic operations with the local disk file system such as: put, get, delete, and exists. With the Storage facade it actually wraps a much more complex third party package called Flysystem which lets you work with various storage Systems including local, Amazon S3, FTP, etc. Here is a table that shows the comparison between Laravel Storage and File Facades:

FeaturesStorage FacadeFile Facade
Basic File Operations
Disk Selection
Temporary URLs
Pre-Signed URLs
Cloud Storage Integrations
Visibility Management
URL Generation
File Metadata
Directory Management
Copy and Move
Stream Support

Thus, the Storage facade offers everything the File facade does. Here is a bit more information about each:

  1. Disk Selection: allows you to specify different storage disks
  2. Temporary URLs: generate temporary URLs for files stored
  3. Pre-Signed URLs: generate pre-signed URLs for file uploads and downloads
  4. Cloud Storage Integrations: integrate with Amazon S3, Google Cloud, and others
  5. Visibility Management: files can be public or private
  6. URL Generation: generate URLs for accessing files
  7. File Metadata: Retrieve metadata such as size and last modified time
  8. Directories: create and delete directories
  9. Copy and Move: copy and move files within or across disks
  10. Stream Support: store files using streams for efficient memory usage with large files

You can easily switch between file systems depending on your environment or configuration. For example with Ozzu I utilize the Storage System with many of the user-based images such as avatars, post uploads, etc. Locally in my development environment everything is file-based stored locally, but on production/live it utilizes Amazon S3 and Cloudfront. The code is identical for both areas, the only difference is how the configuration is setup in the .env files.

One advantage like you mentioned is being able to easily use it with Amazon AWS. Additionally I think you could use it for any number of adapters to work with other systems like FTP or SFTP, and other S3 compatible file systems.

Regarding your package, expanding its capabilities to support various storage systems beyond the local file system could increase its appeal. For this reason I would use the Storage facade.

add a comment
0