使用Laravel 4上传到S3 - 出错

时间:2013-06-04 01:30:05

标签: laravel laravel-4

我正在尝试将图片上传到我的S3存储桶。我正在使用“Aws \ Laravel \ AwsServiceProvider”,我收到此错误:

Guzzle \ Common \ Exception \ InvalidArgumentException
Unknown type passed to configuration loader: integer

我正在关注文档。这是aws.php文件的内容:

return array(
  'key'    => '1AW0WZEW23...',
  'secret' => 'SSz0H69JEAselT...',
  'region' => Aws\Common\Enum\Region::US_WEST_2,
);

我在控制器中添加了这个:

$path = public_path('public') . '/uploads/profile_pics/';
$ext = Input::file('profile_pic')->getClientOriginalName();
$fn = $randfile . '_' . $ext;

$s3 = App::make('aws')->get('s3');
$s3->putObject(array(
  'Bucket'     => 'nestr_profile_pics',
  'Key'        => $fn,
  'SourceFile' => $path,
));

2 个答案:

答案 0 :(得分:2)

我猜你得到这个错误b / c你的aws.php配置文件没有以php脚本标签开头

<?php
return array(
'key'    => '1AW0WZEW23...',
'secret' => 'SSz0H69JEAselT...',
'region' => Aws\Common\Enum\Region::US_WEST_2,
); 

因此配置数组没有传递到Guzzle。

答案 1 :(得分:0)

这是Laravel的CDN资产管理器包,默认情况下支持Amazon S3。

<强> https://github.com/Vinelab/cdn

通过Composer安装:

    {
    "require": {
        "vinelab/cdn": "*"
    }

添加您的CDN凭证:

        'credentials' => [
            'key'    => '',
            'secret'    => '',
        ],

        'buckets' => [
            'bucket-name-here' => '*',
        ]

指定要上载的目录,扩展名,文件和模式

'include'    => [
    'directories'   => ['public/dist'],
    'extensions'    => ['.js', '.css', '.yxz'],
    'patterns'      => ['**/*.coffee'],
],

还指定要忽略的内容

'exclude'    => [
    'directories'   => ['public/uploads'],
    'files'         => [''],
    'extensions'    => ['.TODO', '.txt'],
    'patterns'      => ['src/*', '.idea/*'],
    'hidden'        => true, // ignore hidden files
],

USAGE:

  1. 运行此artisan命令将资源推送到CDN。

    php artisan cdn:push

  2. 在您的视图或代码中的任何其他位置使用以下内容:

    {{Cdn :: asset('public / assets / js / script.js')}}

    {{Cdn :: asset('public / assets / css / main.css')}}