PHPackages                             tourze/tus-upload-server-bundle - 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. tourze/tus-upload-server-bundle

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

tourze/tus-upload-server-bundle
===============================

TUS (Tus Resumable Upload) 文件上传服务端实现包

1.1.0(4mo ago)00MITPHPCI passing

Since Nov 1Pushed 4mo agoCompare

[ Source](https://github.com/tourze/tus-upload-server-bundle)[ Packagist](https://packagist.org/packages/tourze/tus-upload-server-bundle)[ RSS](/packages/tourze-tus-upload-server-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (34)Versions (4)Used By (0)

TUS Upload Server Bundle
========================

[](#tus-upload-server-bundle)

[![PHP Version](https://camo.githubusercontent.com/7535257ca228724c93658bd52583d4e47a9bab02c356abf6e54c1d575f2151e6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312532422d626c75652e737667)](https://www.php.net/)[![License](https://camo.githubusercontent.com/932d8406e99a0c5582ea952bd69a5bb95b3f0fd604788b518c40ea63020be064/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f746f75727a652f7068702d6d6f6e6f7265706f)](LICENSE)
[![Build Status](https://camo.githubusercontent.com/9188cedcadf69c714c7a849f20a9fe3ac95d4c5d15f2f915f59b2d1e4a61c2bc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f75727a652f7068702d6d6f6e6f7265706f2f63692e796d6c)](https://github.com/tourze/php-monorepo/actions)[![Code Coverage](https://camo.githubusercontent.com/9cb168340a6d5a1bdda8e16dafe8eed3d60f1441986fb63de17bff84ee6a18f0/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f7068702d6d6f6e6f7265706f)](https://codecov.io/gh/tourze/php-monorepo)

[English](README.md) | [中文](README.zh-CN.md)

A Symfony bundle implementing the [TUS resumable upload protocol](https://tus.io/) version 1.0.0.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Configuration](#configuration)
- [Dependencies](#dependencies)
- [Usage](#usage)
- [Advanced Usage](#advanced-usage)
- [Commands](#commands)
- [Services](#services)
- [Events](#events)
- [Testing](#testing)
- [Security Considerations](#security-considerations)
- [License](#license)

Features
--------

[](#features)

- Complete TUS 1.0.0 protocol implementation
- File storage using Flysystem (defaults to local filesystem)
- Database storage for upload metadata
- Support for upload expiration and cleanup
- Checksum validation (MD5, SHA1, SHA256)
- CORS support for browser uploads
- Configurable upload size limits

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

[](#installation)

```
composer require tourze/tus-upload-server-bundle
```

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

[](#configuration)

Add the bundle to your `config/bundles.php`:

```
return [
    // ...
    Tourze\TusUploadServerBundle\TusUploadServerBundle::class => ['all' => true],
];
```

Configure the bundle using environment variables in your `.env` file:

```
# Storage path for uploaded files (defaults to /tmp/tus-uploads)
TUS_UPLOAD_STORAGE_PATH=/var/tus-uploads

# Upload path for service (defaults to /tmp/tus-uploads)
TUS_UPLOAD_PATH=/var/tus-uploads
```

Configure routing manually or use the controller service directly. The bundle provides a `TusUploadController` that can be accessed at your desired paths through your application's routing configuration.

Dependencies
------------

[](#dependencies)

This bundle requires the following dependencies:

### Core Dependencies

[](#core-dependencies)

- **PHP 8.1+** - Required for modern PHP features and type declarations
- **Symfony 6.4+** - Framework foundation
- **Doctrine ORM 3.0+** - For database entity management
- **League Flysystem 3.10+** - File storage abstraction layer

### Symfony Components

[](#symfony-components)

- `symfony/config` - Configuration system
- `symfony/console` - Command line interface
- `symfony/dependency-injection` - Service container
- `symfony/framework-bundle` - Core framework bundle
- `symfony/http-foundation` - HTTP abstractions
- `symfony/routing` - URL routing system
- `symfony/validator` - Data validation

### Optional Dependencies

[](#optional-dependencies)

- **Redis/Memcached** - For distributed locking (recommended for production)
- **AWS S3/Google Cloud** - For cloud file storage
- **Database** - MySQL, PostgreSQL, or SQLite for metadata storage

Database Setup
--------------

[](#database-setup)

Create and run the migration for the Upload entity:

```
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
```

Usage
-----

[](#usage)

### Endpoints

[](#endpoints)

The bundle provides the following endpoints:

- `OPTIONS /tus/files` - Get server capabilities
- `POST /tus/files` - Create a new upload
- `HEAD /tus/files/{uploadId}` - Get upload info
- `PATCH /tus/files/{uploadId}` - Upload file chunk
- `DELETE /tus/files/{uploadId}` - Delete upload

### JavaScript Client Example

[](#javascript-client-example)

```
// Create upload
const response = await fetch('/tus/files', {
    method: 'POST',
    headers: {
        'Tus-Resumable': '1.0.0',
        'Upload-Length': file.size,
        'Upload-Metadata': `filename ${btoa(file.name)},filetype ${btoa(file.type)}`
    }
});

const uploadUrl = response.headers.get('Location');

// Upload file in chunks
const chunkSize = 1024 * 1024; // 1MB chunks
let offset = 0;

while (offset
