PHPackages                             xakki/laravel-file-uploader - 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. xakki/laravel-file-uploader

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

xakki/laravel-file-uploader
===========================

Chunked file uploader package for Laravel 10-12.

0.2(5mo ago)021Apache-2.0PHPPHP ^8.3|^8.4|^8.5CI passing

Since Dec 13Pushed 5mo agoCompare

[ Source](https://github.com/Xakki/laravel-file-uploader)[ Packagist](https://packagist.org/packages/xakki/laravel-file-uploader)[ RSS](/packages/xakki-laravel-file-uploader/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (9)Versions (2)Used By (0)

Laravel File Uploader
=====================

[](#laravel-file-uploader)

> Fast, secure and convenient downloader **of any files** for **Laravel 10+** (PHP **8.3+** ) with a modern JS widget.
> Supports **chunked upload** (the chunk size is configured in the config, 1 MB by default), **Drag&amp;Drop**, list of uploaded files (size/date), **copying a public link**, **soft deletion to trash** with TTL auto-cleanup, localization **en/ru**, flexible configuration and work with any disks (including **s3/cloudfront**).

[![Packagist](https://camo.githubusercontent.com/002c8373eb59360179ba6d02dfb835f21526b02b09460bba96d93f92a96ae0bf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7061636b61676973742d78616b6b692532466c61726176656c2d2d66696c652d2d75706c6f616465722d626c7565)](#%D1%83%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B0)[![Laravel](https://camo.githubusercontent.com/12e6a44c1a30425829945fa267b6a20e85c9f62642f4e7517f8467e20e72eee6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302532422d464632443230)](https://laravel.com)[![PHP](https://camo.githubusercontent.com/ec7d8160a4d399e7b82d1bad16b1a8977048f905838f87483fefc3cbd5d0085f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d373737)](https://camo.githubusercontent.com/ec7d8160a4d399e7b82d1bad16b1a8977048f905838f87483fefc3cbd5d0085f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d373737)[![License](https://camo.githubusercontent.com/54a591a708d9e41adc220d00e0caa979b5a5c035327d4eebaab67748cc889e4a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4170616368652d2d322e302d677265656e)](#license)[![CI](https://camo.githubusercontent.com/ee32c1d3760add5b05d7a4aeead531545469bef1d8e64c847aa9cecd4f1cb297/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f43492d476974487562253230416374696f6e732d6c6967687467726579)](#ci--qa--coding-style)[![Coverage](https://camo.githubusercontent.com/f3d820885c8f027e441e39d5faddb352e3d8a9600ef757b1ace3f9373c74582c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f7665726167652d636f6465636f762d6c6967687467726579)](#ci--qa--coding-style)

---

Features
--------

[](#features)

- 🚀 **Chunks**: sending a file in parts, **the chunk size is configurable** (`chunk_size`), default is **1 MB**.
- 🌍**i18n**: **en** (default), **ru**.
- \***Service Provider**: an autodiscaver, publishing assets/config/locales.
- 📦 **Any disks**: default is `files`; there are ready-made recipes for **s3/CloudFront** (public/private).
- 🎨**Pop-up widget**: for uploading files.
    - 🖱️**Drag &amp; Drop** + file selection.
    - 📋**File list**: name, size, date, **copy public link** in one click, delete.
    - 🧹**Deletion to the trash** (soft-delete) + auto-cleaning by **TTL** (default is 30 days).
    - 🔐 **Access via middleware** (default is `web` + `auth`) - changes in the config.

---

Content
-------

[](#content)

- [Installation](#installation)
- [Configuration](#configuration)
- [Integration with S3 / CloudFront](#integration-with-s3--cloudfront)
- [Widget (JS)](#widget-js)
- [Routes and API](#routes-and-api)
- [Delete and Trash](#delete-and-trash)
- [Localization (i18n)](#localization-i18n)
- [PHP Service](#php-service)
- [Security](#security)
- [Performance](#performance)
- [FAQ](#faq)
- [Troubleshooting](#troubleshooting)
- [CI / QA / Coding Style](#ci--qa--coding-style)
- [Roadmap](#roadmap)
- [Contributing](#contributing)
- [License](#license)
- [Credits](#credits)

---

Installation
------------

[](#installation)

```
composer require xakki/laravel-file-uploader
```

If the auto-finder is disabled, add the provider to `config/app.php `:

```
'providers' => [
    Xakki\LaravelFileUploader\Providers\FileUploaderServiceProvider::class,
],
```

Publish assets, and translations.:

```
php artisan vendor:publish --tag=file-uploader-assets
php artisan vendor:publish --tag=file-uploader-translations
```

Make a public symlink (if not already created):

```
php artisan storage:link --relative
```

> 💡 **The default disk is `public`**. Make sure that it is defined in `config/filesystems.php `.

---

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

[](#configuration)

Basic usage by env. Hire available env:

```
FILE_UPLOADER_DISK=public
FILE_UPLOADER_DIRECTORY=uploads
FILE_UPLOADER_TEMPORARY_DIRECTORY=uploads/.chunks
FILE_UPLOADER_METADATA_DIRECTORY=uploads/.meta
FILE_UPLOADER_TRASH_DIRECTORY=uploads/.trash
FILE_UPLOADER_CHUNK_SIZE=1048576
FILE_UPLOADER_MAX_SIZE=52428800
FILE_UPLOADER_ALLOWED_EXTENSIONS=pdf,docx,txt,jpeg,gif,png,webp,application/octet-stream:*,application/zip:zip,application/x-zip-compressed:zip
FILE_UPLOADER_TRASH_TTL_DAYS=30
FILE_UPLOADER_DEFAULT_LOCALE=en

```

The file: `config/file-uploader.php ' (redefine if necessary). Optional publish configs:

```
php artisan vendor:publish --tag=file-uploader-config
```

`FILE_UPLOADER_ALLOWED_EXTENSIONS` accepts a comma-separated list of extensions. You can also bind MIME types to specific extensions using the `mime:extension` format (set `*` as the extension to skip the extension check when the MIME matches). For example, the default configuration is equivalent to:

```
'allowed_extensions' => [
    'pdf',
    'docx',
    'txt',
    'jpeg',
    'gif',
    'png',
    'webp',
    'zip',
    'rar',
    'gz',
    'application/octet-stream' => '*',
    'application/zip' => 'zip',
    'application/x-zip-compressed' => 'zip',
    'application/x-rar-compressed' => 'rar',
    'application/vnd.rar' => 'rar',
    'application/gzip' => 'gz',
    'application/x-gzip' => 'gz',
],
```

> **About the size of the chunk**: the client takes the `chunk_size` from the `/init` response, because the value change in the config is automatically picked up at the front.

### Access control options

[](#access-control-options)

```
'allow_delete_all_files' => false, // Allow everyone to delete all files when true
'full_access' => [
    'users' => [/* user IDs with full access */],
    'roles' => [/* role names checked via hasAnyRole/hasRole/getRoleNames */],
],
```

- When both arrays are empty (default), only the author of the file can delete it.
- The widget hides the delete button for foreign files unless `allow_delete_all_files` is enabled or the current user has full access.

---

Integration with S3 / CloudFront
--------------------------------

[](#integration-with-s3--cloudfront)

Below are two proven scenarios.

### Option A: S3 + CloudFront Public tank as CDN (simple public URLs)

[](#option-a-s3--cloudfront-public-tank-as-cdn-simple-public-urls)

`.env`:

```
FILESYSTEM_DISK=s3
AWS_ACCESS_KEY_ID=...
AWS_SECRET_ACCESS_KEY=...
AWS_DEFAULT_REGION=eu-central-1
AWS_BUCKET=my-public-bucket
AWS_URL=https://dxxxxx.cloudfront.net
AWS_USE_PATH_STYLE_ENDPOINT=false
```

`config/filesystems.php ` (fragment of the s3 driver):

```
's3' => [
    'driver' => 's3',
    'key' => env('AWS_ACCESS_KEY_ID'),
    'secret' => env('AWS_SECRET_ACCESS_KEY'),
    'region' => env('AWS_DEFAULT_REGION'),
    'bucket' => env('AWS_BUCKET'),
    'url' => env ('AWS_URL'), / / < -- cloudfront domain here
    'visibility' => 'public',
    'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
],
```

`config/file-uploader.php`:

```
'disk' => 's3',
'public_url_resolver' => null, / / Storage:: url () returns the CloudFront URL
```

> **Summary:** `Storage:: url (.path)` will build .l based on `aws\_url' (CloudFront domain).

---

### Option B: S3 + CloudFront Private Tank with **signed links**

[](#option-b-s3--cloudfront-private-tank-with-signed-links)

If the bucket is private and file access requires a signature, use one of two paths:

**B1. S3 pre-signed (temporary) URLs:**

- Create a temporary URL in the controller/service along with 'Storage:: url()`:

    ```
    $url = Storage::disk('s3')->temporaryUrl($path, now()->addMinutes(10));
    ```
- Return it to the client (widget/listing).
- - - Plus\*\*: simple and regular. **Minus**: The URL will be s3 format, not CloudFront.

**B2. CloudFront Signed URL (recommended if you need a CDN domain):**

1. Specify in ' config / file-uploader.php ` **public URL resolver** (string callable; it is convenient to put the class in a package/project):

```
'public_url_resolver' => \App\Support\FileUrlResolvers\CloudFrontSignedResolver::class.'@resolve',
```

2. Implement `CloudFrontSignedResolver' (example):

```
