Laravel 5.3亚马逊s3上传问题

时间:2016-09-10 20:55:33

标签: php laravel amazon-s3 laravel-5.3

所以我最近一直在研究一个项目而且我设法试图将文件上传到s3,我之前已经在以前的网站上做过这样的事情并且很好但是这个似乎证明了一点棘手。

我正在尝试将通过表单发送的文件(pdf)上传到s3上的'horsebeach'存储桶,点击表单上的提交后,页面就会冻结。

这是我的上传代码:

 $file = $request->file('attachment');
 $s3 = Storage::disk('s3');
 $s3->put($file->hashName(), file_get_contents($file));

在我的EventController中:

public function newEvent(Request $request){
      // in here
}

更改为本地存储工作正常,文件存储在我的应用程序存储中。

这是我的表格,有助于:

<form action="{{URL::to('events/new')}}" method="post" enctype="multipart/form-data">
    {{ csrf_field() }}
    <div class="form_inputs clearfix">
        <div class="row-fluid">
            <div class="span2">
                <label class="control-label">Event Title:</label>
            </div>
            <div class="span10">
                <input type="text" name="event-title" placeholder="Event Title" class="span11"/>
            </div>
        </div>
    </div>
    @if ($errors->has('event-title'))
    <span class="help-block">
        <strong>{{ $errors->first('event-title') }}</strong>
    </span>
    @endif
    <div class="form_inputs clearfix">
        <div class="row-fluid">
            <div class="span2">
                <label class="control-label">Begin Date:</label>
            </div>
            <div class="span2">
                <input type="text" name="begin-date" placeholder="e.g 27-02-2016" class="span11 dpicker">
            </div>
        </div>
    </div>
    @if ($errors->has('begin-date'))
    <span class="help-block">
        <strong>{{ $errors->first('begin-date') }}</strong>
    </span>
    @endif
    <div class="form_inputs clearfix">
        <div class="row-fluid">
            <div class="span2">
                <label class="control-label">End Date:</label>
            </div>
            <div class="span2">
                <input type="text" name="end-date" placeholder="e.g 27-02-2016" class="span11 dpicker">
            </div>
        </div>
    </div>
    @if ($errors->has('end-date'))
    <span class="help-block">
        <strong>{{ $errors->first('end-date') }}</strong>
    </span>
    @endif
    <div class="form_inputs clearfix">
        <div class="row-fluid">
            <div class="span2">
                <label class="control-label">Location:</label>
            </div>
            <div class="span10">
                <input type="text" name="location" placeholder="e.g Dave's house" class="span11"/>
            </div>
        </div>
    </div>
    @if ($errors->has('location'))
    <span class="help-block">
        <strong>{{ $errors->first('location') }}</strong>
    </span>
    @endif
    <div class="form_inputs clearfix">
        <div class="row-fluid">
            <div class="span2">
                <label class="control-label">Fee:</label>
            </div>
            <div class="span10">
                <div class="input-prepend">
                    <span class="add-on">£ </span> <input type="text" id='fee' name="fee" placeholder="2000" style="width: 87%">
                </div>
            </div>
        </div>
    </div>
    @if ($errors->has('fee'))
    <span class="help-block">
        <strong>{{ $errors->first('fee') }}</strong>
    </span>
    @endif
    <div class="form_inputs clearfix">
        <div class="row-fluid">
            <div class="span2">
                <label class="control-label">Colour:</label>
            </div>
            <div class="span10">
                <div class="input-prepend">
                    <input type="text" name="colour" placeholder="" id="color1" class="color1">
                </div>
            </div>
        </div>
    </div>
    @if ($errors->has('colour'))
    <span class="help-block">
        <strong>{{ $errors->first('colour') }}</strong>
    </span>
    @endif
    <div class="form_inputs clearfix">
        <div class="row-fluid">
            <div class="span2">
                <label class="control-label">Description:</label>
            </div>
            <div class="span10">
                <textarea rows="3" name="description" placeholder="What's going down?" class="span11 elastic"></textarea>
            </div>
        </div>
    </div>
    <div class="form_inputs clearfix">
        <div class="row-fluid">
            <div class="span2">
                <label class="control-label">Confirmed?</label>
            </div>
            <div class="span10">
                <input type="checkbox" name="confirmed" class="radio1">
            </div>
        </div>
    </div>
    <div class="form_inputs clearfix">
        <div class="row-fluid">
            <div class="span2">
                <label class="control-label">Attachments:</label>
            </div>
            <div class="span10">
                <input id="fileupload" type="file" name="attachment"/>
            </div>
        </div>
    </div>
    <div class="form_inputs">
        <input type="submit" name="create-event" value="Create Event" class="btn btn-info"/>
    </div>
</form>

配置文件:

    's3' => [
        'driver' => 's3',
        'key'    => env('AWS_KEY'),
        'secret' => env('AWS_SECRET'),
        'region' => env('AWS_LOCATION'),
        'bucket' => 'horsebeach',
    ],

composer.json:

"league/flysystem-aws-s3-v3": "~1.0"

1 个答案:

答案 0 :(得分:1)

您确定要提取aws/aws-sdk-php-laravel吗?

我的项目中安装了以下内容:

    "aws/aws-sdk-php-laravel": "^3.1",
    "graham-campbell/flysystem": "^3.0",
    "league/flysystem-aws-s3-v3":"~1.0",

另外,请关注storage/logs/laravel.log以查看最新情况。