PHPackages                             aarondfrancis/r2proxy - 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. aarondfrancis/r2proxy

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

aarondfrancis/r2proxy
=====================

A Laravel package for proxying Cloudflare R2 files with public path whitelisting

v0.1.0(5mo ago)4753↓90.9%MITPHPPHP ^8.2CI passing

Since Dec 28Pushed 4mo agoCompare

[ Source](https://github.com/aarondfrancis/r2proxy)[ Packagist](https://packagist.org/packages/aarondfrancis/r2proxy)[ RSS](/packages/aarondfrancis-r2proxy/feed)WikiDiscussions main Synced 1w ago

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

R2 Proxy for Laravel
====================

[](#r2-proxy-for-laravel)

Serve files from a **private** Cloudflare R2 bucket through your Laravel application.

This package proxies whitelisted paths from a private R2 bucket, allowing you to serve certain files publicly while keeping everything else secure. No need to make your bucket public or configure complex access policies—just define which path prefixes should be accessible and the package handles the rest with configurable caching headers.

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

[](#installation)

```
composer require aarondfrancis/r2proxy
```

Publish the config file:

```
php artisan vendor:publish --tag=r2proxy-config
```

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

[](#configuration)

If you don't already have an R2 disk configured, follow the [Laravel S3 driver documentation](https://laravel.com/docs/filesystem#amazon-s3-compatible-filesystems) to set one up.

Once you have an R2 disk, change the driver from `s3` to `r2_public`:

```
// config/filesystems.php
'r2' => [
    // Change from 's3' to 'r2_public'
    'driver' => 'r2_public',
    // The route prefix for proxied files (e.g. /r2/images/photo.jpg)
    'url' => '/r2/',
    // ... rest of your existing R2 config
],
```

Then configure which disks should be proxied in `config/r2proxy.php`:

```
use AaronFrancis\R2Proxy\PathValidator;

return [
    'disks' => [
        'r2' => [
            'path_validator' => PathValidator::directories('images', 'videos'),
        ],
    ],
];
```

### Multiple Disks

[](#multiple-disks)

You can proxy multiple disks, each with their own path validator and cache settings:

```
'disks' => [
    'r2' => [
        'path_validator' => PathValidator::directories('images', 'videos'),
    ],
    'r2-assets' => [
        'path_validator' => PathValidator::matches('css/*', 'js/*'),
        'cache' => [
            'max_age' => 86400, // 1 day
        ],
    ],
],
```

Usage
-----

[](#usage)

The `temporaryUrl` method returns a proxy URL for public paths:

```
// Returns /r2/images/photo.jpg (proxied through your app)
$url = Storage::disk('r2')->temporaryUrl('images/photo.jpg', now()->addHour());

// Private paths still get signed S3 URLs
$url = Storage::disk('r2')->temporaryUrl('private/secret.pdf', now()->addHour());
```

### Checking Path Access

[](#checking-path-access)

```
use AaronFrancis\R2Proxy\Filesystem\R2PublicAdapter;

if (R2PublicAdapter::isPathAllowed('images/photo.jpg', 'r2')) {
    // Path is publicly accessible on the 'r2' disk
}
```

### Path Validation Options

[](#path-validation-options)

**Directories** - allow entire directories:

```
use AaronFrancis\R2Proxy\PathValidator;

'path_validator' => PathValidator::directories('images', 'uploads'),
```

**Patterns** - wildcard matching with `*`:

```
'path_validator' => PathValidator::matches('images/*.jpg', 'videos/*.mp4'),
```

Security
--------

[](#security)

Only paths allowed by the path validator are accessible through the proxy. Requests to other paths return a 403 Forbidden response. Directory traversal attacks are blocked regardless of validator configuration.

How It Works
------------

[](#how-it-works)

1. Files in public paths are served through `/{url-prefix}/{path}` routes
2. The controller streams files directly from R2 with proper headers
3. Cache-Control headers are added for browser/CDN caching
4. Private files still use signed S3 URLs via the parent adapter

License
-------

[](#license)

MIT

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance73

Regular maintenance activity

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 93.3% 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

Unknown

Total

1

Last Release

164d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/033238953a59b9223a1bde703b5e4254e63c7412195da1cb9de5af44bf53fc0a?d=identicon)[aarondfrancis](/maintainers/aarondfrancis)

---

Top Contributors

[![aarondfrancis](https://avatars.githubusercontent.com/u/881931?v=4)](https://github.com/aarondfrancis "aarondfrancis (14 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/aarondfrancis-r2proxy/health.svg)

```
[![Health](https://phpackages.com/badges/aarondfrancis-r2proxy/health.svg)](https://phpackages.com/packages/aarondfrancis-r2proxy)
```

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

9782.1M153](/packages/laravel-ai)[unisharp/laravel-filemanager

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

2.1k3.4M80](/packages/unisharp-laravel-filemanager)[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.

45344.0k1](/packages/pressbooks-pressbooks)[moonshine/moonshine

Laravel administration panel

1.3k239.9k72](/packages/moonshine-moonshine)[illuminate/session

The Illuminate Session package.

9938.5M818](/packages/illuminate-session)[illuminate/notifications

The Illuminate Notifications package.

513.0M1.1k](/packages/illuminate-notifications)

PHPackages © 2026

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