定制 hosni/laravel-temporary-urls-minio 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hosni/laravel-temporary-urls-minio

Composer 安装命令:

composer require hosni/laravel-temporary-urls-minio

包简介

Fix temporary url generation when using MinIO as S3 backend

README 文档

README

Latest Version on Packagist Total Downloads License Laravel

🚀 Introduction

By default, Laravel’s temporaryUrl() method works perfectly with S3-compatible storage.
It generates a temporary URL to an object in your S3 bucket, easy peasy!

But when you switch to MinIO, things get a little wild. Temporary URLs might not work if the generated endpoint isn’t directly accessible by your client (browser, mobile app, etc).

You may have run into this when using temporaryUrl() directly, or when a package like spatie/laravel-medialibrary calls $media->getTemporaryUrl() behind the scenes.

From the Laravel documentation:

Warning

Generating temporary storage URLs via the temporaryUrl method may not work when using MinIO if the endpoint is not accessible by the client. , Laravel Filesystem Docs

But here’s the BIG question:

How do you make MinIO’s temporaryUrl() work in Laravel?

This package is your plug-and-play hero! Just install it, and let the magic happen. 🎩✨

📦 Installation

Install the package via Composer:

composer require hosni/laravel-temporary-urls-minio

Laravel will auto-discover the service provider using Package Discovery. No extra steps, just sit back and relax!

⚙️ Configuration

In your .env file, set your MinIO configuration like a boss:

AWS_ACCESS_KEY_ID=minioadmin
AWS_SECRET_ACCESS_KEY=minioadmin
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=my-bucket

# Internal MinIO endpoint (used for signing)
AWS_ENDPOINT=http://minio:9000

# Publicly accessible endpoint (used in signed URLs)
MINIO_PUBLIC_URL=https://storage.example.com

Next, in config/filesystems.php:

'disks' => [
    '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'),
        'endpoint' => env('AWS_ENDPOINT'),
        'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
        'throw' => false,
        'report' => false,

    /**
     * Add this to your s3 disk configuration.
     * This is where the magic happens! 🪄
     */
    'temporary_url' => env('MINIO_PUBLIC_URL'), // 👈 used for rewriting signed URLs
    ],
],

🛠 Usage

Just use Laravel’s filesystem like you always do:

use Illuminate\Support\Facades\Storage;

$url = Storage::disk('minio')->temporaryUrl(
    'uploads/myfile.jpg',
    now()->addMinutes(5)
);

return $url;

👉 The returned $url will always be valid and accessible from your client. You can thank me later! 😎

You can also use this with spatie/laravel-medialibrary:

$mediaItems = $yourModel->getMedia();
$temporaryS3Url = $mediaItems[0]->getTemporaryUrl(now()->addMinutes(5));

No need to install packages like coreproc/laravel-minio-media-library-provider, which take a different (and less effective) approach! Their solution simply returns the MinIO endpoint URL, which is only accessible inside your Docker network, not so helpful if you want to share files with the outside world. 😅

With this package, your temporary URLs are always accessible, inside or outside Docker. No hacks, no headaches, just happy URLs!

🔍 How It Works

  1. Laravel signs the request using your internal MinIO endpoint (AWS_ENDPOINT).
  2. This package swoops in and intercepts the signed URL.
  3. It rewrites the host from the internal endpoint to the public URL you configured (MINIO_PUBLIC_URL).
  4. The result? A valid, signed, publicly accessible temporary URL. 🎉

✅ Example

If your .env looks like this:

AWS_ENDPOINT=http://minio:9000
MINIO_PUBLIC_URL=https://cdn.example.com

Then, when you do:

Storage::disk('minio')->temporaryUrl('photos/pic.jpg', now()->addMinutes(10));

You’ll get something like:

https://cdn.example.com/photos/pic.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=...

Instead of:

http://minio:9000/photos/pic.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=...

📖 Credits

📝 License

This package is open-sourced software, licensed under the MIT license.

hosni/laravel-temporary-urls-minio 适用场景与选型建议

hosni/laravel-temporary-urls-minio 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.46k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2025 年 09 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「s3」 「aws」 「laravel」 「minio」 「temporary-urls」 「RustFS」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 hosni/laravel-temporary-urls-minio 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 hosni/laravel-temporary-urls-minio 我们能提供哪些服务?
定制开发 / 二次开发

基于 hosni/laravel-temporary-urls-minio 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5.46k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-08