简体   繁体   中英

Laravel 5.3 Amazon s3 upload issue

So I've been working on a project recently and I've managed to get stuck trying to upload a file to s3, I've done this before on previous sites and it's been fine but this one seems to proving a little tricky.

I'm trying to upload a file (pdf) that's been sent through a form to my 'horsebeach' bucket on s3, after clicking submit on the form, the page just freezes.

Here's my upload code:

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

Inside my EventController:

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

Changing to local storage works just fine and the file is stored in my app storage.

Here's my form incase that helps:

<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>

Config file:

    '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"

Did you make sure to pull in aws/aws-sdk-php-laravel ?

I have the following installed in my project:

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

Also, tail your storage/logs/laravel.log to see whats going on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM