PHPackages                             andreinocenti/laravel-file-s3-like - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. andreinocenti/laravel-file-s3-like

ActiveLibrary[File &amp; Storage](/categories/file-storage)

andreinocenti/laravel-file-s3-like
==================================

A package to upload, update, delete, purge a S3 like storage via Laravel

v1.6(2mo ago)3370mitPHPPHP ^8.2

Since Jun 17Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/andreinocenti/laravel-file-s3-like)[ Packagist](https://packagist.org/packages/andreinocenti/laravel-file-s3-like)[ RSS](/packages/andreinocenti-laravel-file-s3-like/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (26)Versions (14)Used By (0)

Laravel Package - Files to S3 Like Cloud Storage
================================================

[](#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 sending a file URL, a form uploaded file (UploadedFile) or a base64 file string.

It supports generating a presigned url.

Support
-------

[](#support)

Currently supports:

- **Digital Ocean SPACES**
- **Google Cloud Storage (GCS)**

Configuration
-------------

[](#configuration)

You should install it via composer:

`composer require andreinocenti/laravel-file-s3-like`

### 1. Digital Ocean Spaces

[](#1-digital-ocean-spaces)

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 in `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,
],
```

### 2. Google Cloud Storage (GCS)

[](#2-google-cloud-storage-gcs)

To use GCS, you need to install the required dependencies:

`composer require google/cloud-storage spatie/laravel-google-cloud-storage`

To see more GCS filesystem configs check: `https://github.com/spatie/laravel-google-cloud-storage`

For uniform bucket level access use: `'visibility_handler' => \League\Flysystem\GoogleCloudStorage\UniformBucketLevelAccessVisibility::class`

Then configure the disk in `config/filesystem.php`:

```
'gcs' => [
    'driver' => 'gcs',
    'project_id' => env('GOOGLE_CLOUD_PROJECT_ID', 'your-project-id'),
    'key_file_path' => env('GOOGLE_APPLICATION_CREDENTIALS'), // Path to service account json file
    'bucket' => env('GOOGLE_CLOUD_STORAGE_BUCKET', 'your-bucket'),
    'path_prefix' => env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX', null), // Optional: prefix for all files
    'storage_api_uri' => env('GOOGLE_CLOUD_STORAGE_API_URI', null), // Optional: custom API URI
    'api_endpoint' => env('GOOGLE_CLOUD_STORAGE_API_ENDPOINT', null), // Optional: custom API endpoint
    'visibility_handler' => \League\Flysystem\GoogleCloudStorage\UniformBucketLevelAccessVisibility::class, // for uniform bucket level access
    'throw' => false,
],
```

Ensure you have your Google Cloud Service Account JSON key file reachable and the path correctly set in `GOOGLE_APPLICATION_CREDENTIALS` environment variable.

Usage
-----

[](#usage)

### Digital Ocean Spaces

[](#digital-ocean-spaces)

You can use the `FileS3LikeSpaces` facade:

```
use AndreInocenti\LaravelFileS3Like\Facades\FileS3LikeSpaces;

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

Or using the generic `FileS3Like` facade:

```
use AndreInocenti\LaravelFileS3Like\Facades\FileS3Like;

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

### Google Cloud Storage (GCS)

[](#google-cloud-storage-gcs)

Use the `FileS3Like` facade with the `gcs` repository:

```
use AndreInocenti\LaravelFileS3Like\Facades\FileS3Like;

FileS3Like::repository('gcs')
    ->disk('gcs') // The disk name configured in config/filesystems.php
    ->directory('uploads')
    ->upload($file, 'profile-picture');
```

### Upload from stream

[](#upload-from-stream)

Use `uploadStream` when you already have an open readable stream and want to avoid loading the full file into memory.

```
use AndreInocenti\LaravelFileS3Like\Facades\FileS3Like;

$stream = fopen(storage_path('app/large-video.mp4'), 'r');

$diskFile = FileS3Like::repository('spaces') // or 'gcs'
    ->disk('spaces')
    ->directory('videos')
    ->uploadStream($stream, 'large-video.mp4', 'video/mp4');

fclose($stream);
```

Use `saveStream` when you want the same semantics as `save`:

- `spaces`: upload and purge CDN cache
- `gcs`: same behavior as upload

```
use AndreInocenti\LaravelFileS3Like\Facades\FileS3LikeSpaces;

$stream = fopen(storage_path('app/banner.png'), 'r');

$diskFile = FileS3LikeSpaces::disk('spaces-disk')
    ->directory('images')
    ->saveStream($stream, 'banner.png', 'image/png');

fclose($stream);
```

Methods / Accessors
-------------------

[](#methods--accessors)

### FileS3Like and its repositories (Eg: FileS3LikeSpaces, FileS3LikeGCS)

[](#files3like-and-its-repositories-eg-files3likespaces-files3likegcs)

  Method Description   repository(string $repository): self  The repository is the storage service you want to use. Supported: `spaces`, `gcs`.    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](#diskfile)  Upload the file to the storage. If $filename is empty, the name of the file will be a UUID hash.    uploadStream(resource $stream, string $filename, ?string $mime = null): [DiskFile](#diskfile)  Upload an already opened readable stream directly to the storage disk. Use this for large files to avoid loading the whole file into memory.    save(string $repository): [DiskFile](#diskfile)  Upload and update the file on the storage disk. For **Spaces**: Purges the CDN cache. For **GCS**: Same as upload (GCS requires different API for CDN invalidation). If a file with the same name already exists, it will be overwritten. If $filename is empty, the name of the file will be a UUID hash.    saveStream(resource $stream, string $filename, ?string $mime = null): [DiskFile](#diskfile)  Save an already opened readable stream to the storage disk. For **Spaces**: uploads and purges CDN cache. For **GCS**: same behavior as `uploadStream`.    presignedUrl(string $filepath, ?string $filename = null, int $expiration = 900, string|null $fileType = null, bool $public = false): object  Create a presigned URL for direct upload to the path in `$filepath` (relative to the configured folder). `$filename` is optional and defaults to a UUID; extension is inferred from `$fileType` or the filename. `$fileType` accepts a mime type or extension (eg: `image/png`, `jpg`, `image/*`) and is used to set Content-Type. `$public` toggles the ACL between `private` (default) and `public-read` (Note: GCS presigned URLs handle public access differently, but the flag sets the ACL header if supported). `$expiration` is in seconds; default is 900 (15 minutes).    purge(string $filepath): self  Purges a CDN cache of a file. **Spaces:** Calls DigitalOcean CDN API. **GCS:** No-op (use Google Cloud CDN invalidation API separately).    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  ### Presigned URL usage

[](#presigned-url-usage)

Use `presignedUrl` when you need a temporary URL for clients to upload directly to the bucket.

```
use AndreInocenti\LaravelFileS3Like\Facades\FileS3Like;

$upload = FileS3Like::repository('gcs') // or 'spaces'
    ->disk('gcs')
    ->directory('uploads')
    ->presignedUrl(
        filepath: 'avatars',         // directory inside the configured folder
        filename: 'profile.png',     // optional; defaults to UUID
        expiration: 600,             // seconds
        fileType: 'image/png',       // mime or extension; sets Content-Type
        public: true,                // optional; false keeps it private
    );

return response()->json($upload);
```

The returned `Fluent` object contains the presigned URL and useful metadata:

```
{
  "presigned_url": "https://storage.googleapis.com/...",
  "key": "uploads/avatars/profile.png",
  "public_url": "https://storage.googleapis.com/your-bucket/uploads/avatars/profile.png",
  "expires": "2024-04-30 12:34:56",
  "headers": {
    "Content-Type": "image/png",
    "ACL": "public-read"
  },
  "accepted_mime": "image/png",
  "accepted_ext": "png"
}
```

Send the provided `headers` with the upload request to ensure the ACL and mime type are applied.

### DiskFile

[](#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: "".    getExtension(): string  Returns the file extension. Eg: "jpg".

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance88

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~113 days

Recently: every ~36 days

Total

13

Last Release

60d ago

PHP version history (3 changes)v1PHP ^8.0

v1.0.5PHP ^8.1

v1.2PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/9d5b3ad27cc2ab495bd40b9837f085b35efd442cbd88ceac5971f273ecdd88a6?d=identicon)[andreinocenti](/maintainers/andreinocenti)

---

Top Contributors

[![andreinocenti](https://avatars.githubusercontent.com/u/39701679?v=4)](https://github.com/andreinocenti "andreinocenti (57 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/andreinocenti-laravel-file-s3-like/health.svg)

```
[![Health](https://phpackages.com/badges/andreinocenti-laravel-file-s3-like/health.svg)](https://phpackages.com/packages/andreinocenti-laravel-file-s3-like)
```

###  Alternatives

[unisharp/laravel-filemanager

A file upload/editor intended for use with Laravel 5 to 10 and CKEditor / TinyMCE

2.2k3.3M74](/packages/unisharp-laravel-filemanager)[illuminate/filesystem

The Illuminate Filesystem package.

15261.6M2.6k](/packages/illuminate-filesystem)[spatie/laravel-google-cloud-storage

Google Cloud Storage filesystem driver for Laravel

2408.9M13](/packages/spatie-laravel-google-cloud-storage)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1225.0k10](/packages/fleetbase-core-api)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

44643.1k1](/packages/pressbooks-pressbooks)[spatie/laravel-backup-server

Backup multiple applications

17016.7k1](/packages/spatie-laravel-backup-server)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
