braunson/laravel-rackspace-cdn 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

braunson/laravel-rackspace-cdn

最新稳定版本:0.5.0

Composer 安装命令:

composer require braunson/laravel-rackspace-cdn

包简介

Updated version of ThomasWelton's because that repo seems to be inactive

README 文档

README

README for Laravel 4.x is here

Installation

Run command in your terminal to include this package as a dependency:

composer require braunson/laravel-rackspace-opencloud

Register the OpenCloud service provider and alias the OpenCloud, Str (removed in Laravel 5.0+) facades by adding it to the providers and aliases arrays in the config/app.php file.

For Laravel 5.5 and later don't need (auto discovery).

For Laravel 5.2 - 5.4:

'providers' => [
    Braunson\LaravelRackspaceCdn\LaravelRackspaceCdnServiceProvider::class
];
'aliases' => [
    'OpenCloud' => Braunson\LaravelRackspaceCdn\Facades\OpenCloud::class,
    'Str' => Illuminate\Support\Str::class,
]

For Laravel 5.1 and earlier:

'providers' => [
    'Braunson\LaravelRackspaceCdn\LaravelRackspaceCdnServiceProvider'
]
'aliases' => [
    'OpenCloud' => 'Braunson\LaravelRackspaceCdn\Facades\OpenCloud',
    'Str' => 'Illuminate\Support\Str',
]

Configuration

Copy the config files into your project by running:

php artisan vendor:publish --provider="Braunson\LaravelRackspaceCdn\LaravelRackspaceCdnServiceProvider"

Edit the config file to include your username, api key, region and url (internal or public).

Usage

Artisan Commands

Upload files via the command line.

Synchronize a whole directory. Copies all files to /public/assets:

php artisan cdn:sync public/assets

Copies all files to /assets trimming 'public' from the path:

php artisan cdn:sync public/assets --trim=public

You can configure your package.json to do this as NPM task:

"scripts": {
    "cdn:sync": "php artisan cdn:sync public/assets --trim=public"
},

The sync command will save a file adjacent to the synchronized directory. It contains the http and https urls for your container. Along with a md5 hash of the directory. In this way when a file changes inside a directory and is reuploaded you get a new cache busted URL.

If you are using the URL helper then it will return a CDN url for a file, if it finds a *.cdn.json file adjacent to one of it's parent directories.

URL::asset('assets/image.jpg');

You should be able to run php artisan cdn:sync public/assets --trim=public before or during a deployment and once complete all files being called by URL::asset() will return a CDN resource.

Upload to CDN

OpenCloud::upload($container, $file, $name = null)
  • $container - (string) Name of the container to upload into;
  • $file - (string / UploadedFile) Path to file, or instance of Symfony\Component\HttpFoundation\File\UploadedFile as returned by Request::file();
  • $name - (string) Optional file name to be used when saving the file to the CDN.

Example:

Route::post('/upload', function()
{ 
    // '\Input' alias was removed from the default aliases in Laravel 5.2+
    if(Request::hasFile('image')){
        $file = OpenCloud::upload('my-container', Request::file('image'));
    }

    $cdnUrl = $file->PublicURL();
    // Do something with $cdnUrlth

    return Redirect::to('/upload');
});

Delete from CDN

OpenCloud::delete($container, $file)

统计信息

  • 总下载量: 38
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-04-19