Laravel Package - Files to S3 Like Cloud Storage

Overview

Laravel Package - Files to S3 Like Cloud Storage

This is a Laravel package that handles and make easy the upload, overwrite, delete, cdn purge of files and directories on AWS S3 like cloud storages.

It supports a form uploaded file (UploadedFile) or a base64 file string

Support

At the actual version it support only Digital Ocean SPACES cloud storage.

In the future I will add new cloud storages support or accept pull requests.

Configuration

You should install it via composer:

composer require andreinocenti/laravel-file-s3-like

This package use the Laravel Illuminate\Support\Facades\Storage facade to handle the files.

So you must config the filesystem AWS like disk that you want to use.

Below the optimal config to be used

config/filesystem.php

'spaces-disk' => [
    'driver' => 's3',
    'key' => env('SPACES_ACCESS_KEY_ID'),
    'secret' => env('SPACES_SECRET_ACCESS_KEY'),
    'region' => env('SPACES_DEFAULT_REGION'),
    'bucket' => env('SPACES_BUCKET'),
    'url' => env('SPACES_URL'),
    'endpoint' => env('SPACES_ENDPOINT'),
    'folder' => env('SPACES_FOLDER'), // This will be the default directory used. It can be empty, if so the default directory will be the bucket root
    'cdn_endpoint' => env('SPACES_CDN_ENDPOINT'), // at Digital Ocean Spaces the CDN is auto set when a file is uploaded. So set here the cdn_endpoint (edge)
    'use_path_style_endpoint' => env('SPACES_USE_PATH_STYLE_ENDPOINT', false),
    'throw' => false,
],

Usage

You can use the FileS3LikeSpaces facade

use AndreInocenti\LaravelFileS3Like\Facades\FileS3LikeSpaces;

FileS3LikeSpaces::disk('spaces-disk')
    ->directory('images')
    ->upload($file, 'new-test');

Or you can use the FileS3Like Facade, if you do you must set the repository() you want to use.

use AndreInocenti\LaravelFileS3Like\Facades\FileS3Like;

FileS3Like::repository('spaces')
    ->disk('spaces-disk')
    ->directory('images')
    ->upload($file, 'new-test');

Methods / Accessors

FileS3Like and its repositories (Eg: FileS3LikeSpaces)

Method Description
repository(string $repository): self The repository is the s3 like service that this package support, that you want to use. Eg.: spaces. Check the Support list
disk(string $disk): self Sets the filesystem disk that the Storage facade will use to handle the files on the cloud storage
directory(string $directory): self The directory in the cloud storage bucket that will be handled. Important: It will concat with the folder configurated in the file filesystem. The folder configuration, is good to have always the same base directory configured, instead of the "directory()" that can change anytime EG.: if folder was configured to be "public", and the directory "images", the final path will be `public/images`.
upload(UploadedFile|string $file, ?string $filename = null): DiskFile Upload the file to the storage. If $filename is empty, the name of the file will be aUUID hash.
save(string $repository): DiskFile Upload and update the file on the space disk, purge cache and return the file url. If a file with the same name already exists, it will be overwritten and the cache will be purged. If it is a new file, it will only be uploaded. If $filename is empty, the name of the file will be aUUID hash.
purge(string $filepath): self Purges a CDN cache of a file. $filename - Inform the file name and path of the file to be purged.
delete(string $filepath): self Delete a file from the cloud storage disk
deleteDirectory(string $filepath): self Recursively delete a directory from the cloud storage disk
directories(string $filepath): array List directories in the directory set
files(string $filepath): array List files in the directory set

DiskFile

DiskFile is a DTO class that is created and delivered when the functions upload or save are called. The class contain accessors that returns some file data.

Method Description
getFilepath(): string Return the file, filepath without the url. Eg: "some/path/to/file.jpg".
getFilename(): string Return the file name. Eg: "file.jpg".
getUrl(): string Returns the full file url. Eg: "https://somedomain.com/some/path/to/file.jpg".
getExtension(): string Returns the file extension. Eg: "jpg".
You might also like...
 Enhance your laravel apps with WhatsApp's Cloud API
Enhance your laravel apps with WhatsApp's Cloud API

Enhance your laravel apps with WhatsApp's Cloud API Use Whatsapp API in your Laravel app! Support us Investing on this package is defintely a good mov

A package to generate YouTube-like IDs for Eloquent models

Laravel Hashids This package provides a trait that will generate hashids when saving any Eloquent model. Hashids Hashids is a small package to generat

This package allows you to render livewire components like a blade component, giving it attributes, slots etc

X-livewire This package allows you to render livewire components like a blade component, giving it attributes, slots etc. Assuming you wanted to creat

A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.
A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.

Install Install via composer. $ composer require olliecodes/laravel-etched-blade Once installed you'll want to publish the config. $ php artisan vendo

Laravel-Mediable is a package for easily uploading and attaching media files to models with Laravel 5.

Laravel-Mediable Laravel-Mediable is a package for easily uploading and attaching media files to models with Laravel. Features Filesystem-driven appro

Laravel Package to generate CRUD Files using TALL Stack
Laravel Package to generate CRUD Files using TALL Stack

tall-crud-generator Laravel Package to generate CRUD Files using TALL Stack Requirements Make sure that Livewire is installed properly on your project

A Laravel package for attachment files to models

Laravel attachmentable package A package for attachment files to models Installation Run the command below to add this package: composer require larav

Package to parse DNA kit files, and import them into Laravel

Package to parse DNA kit files, and import them into Laravel

Package for Laravel that gives artisan commands to setup and edit environment files.
Package for Laravel that gives artisan commands to setup and edit environment files.

Setup and work with .env files in Laravel from the command line NOTE: This doesn't work with Laravel 5 since .env files were changed. This is for Lara

Releases(v1.0.4)
Owner
André G. Inocenti Lobo Viana
André G. Inocenti Lobo Viana
Flysystem storage with local metadata storage for speed and manageability.

Laravel Filer This project was started to scratch my itch on our growing Laravel site: Metadata for all files is stored in a local repository - Suppor

Nick Vahalik 16 May 23, 2022
Google Cloud Storage filesystem driver for Laravel

Google Cloud Storage filesystem driver for Laravel Google Cloud Storage filesystem driver for Laravel. This started as a fork from Superbalist/laravel

Spatie 88 Dec 16, 2022
This package provides an integration with FFmpeg for Laravel. Laravel's Filesystem handles the storage of the files.

Laravel FFMpeg This package provides an integration with FFmpeg for Laravel 6.0 and higher. Laravel's Filesystem handles the storage of the files. Lau

Protone Media 1.3k Jan 1, 2023
A laravel package to generate class files from stub files.

Laravel Stub Generator A php laravel package to generate useable php files from given stub files . Installation Require the package using composer: co

Touhidur Rahman 31 Dec 29, 2022
A Laravel package that allows you to use multiple ".env" files in a precedent manner. Use ".env" files per domain (multi-tentant)!

Laravel Multi ENVs Use multiple .envs files and have a chain of precedence for the environment variables in these different .envs files. Use the .env

Allyson Silva 48 Dec 29, 2022
Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.

Laravel Befriended Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked

Renoki Co. 720 Jan 3, 2023
Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud Messaging (FCM).

Laravel-FCM Introduction Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud M

Rahul Thapa 2 Oct 16, 2022
Removes whitelisted unnecessary files (like tests/docs etc.) from vendor directory

Composer vendor cleanup This is a simple script for the Composer to remove unnecessary files (documentation/examples/tests etc.) from included vendor

Chris 2 Nov 14, 2022
A package that adds view-composer like feature to Inertia.js Laravel adapter

Kinetic A package that adds view-composer like feature to Inertia.js Laravel adapter. Use to be able to share props based on the Inertia component nam

Marvin Quezon 76 Dec 12, 2022
Use Laravel's built-in ORM classes to query cloud resources with Steampipe.

Laravel Steampipe Use Laravel's built-in ORM classes to query cloud resources with Steampipe, an open source CLI to instantly query cloud APIs using S

Renoki Co. 13 Nov 8, 2022