I am trying to store image in S3 bucket and i am using laravel 5.5 i am new and i am stuck here: What i am trying is:
My Controller:
public function imageUploadPost(Request $request)
{
$this->validate($request, [
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$imageName = time().'.'.$request->image->getClientOriginalExtension();
$image = $request->file('image');
$t = Storage::disk('s3')->put($imageName, file_get_contents($image), 'public');
$imageName = Storage::disk('s3')->url($imageName);
return back()
->with('success','Image Uploaded successfully.')
->with('path',$imageName);
}
My routes:
Route::post('s3-image-upload','S3ImageController@imageUploadPost');
My config/filesystems.php
's3' => [
'driver' => 's3',
'key' => env('AccessKeyID'),
'secret' => env('SecretAccessKey'),
'region' => env('region'),
'bucket' => env('mybucket'),
],
And i am getting these values from my env file my .env file looks like:
AccessKeyID=xyz
SecretAccessKey=xyz
region=us-east-2
mybucket=spikessales
Now when i upload file and hit upload button it says :
Encountered a permanent redirect while requesting https://spikessales.s3.us-east-2.amazonaws.com/1519812331.jpg. Are you sure you are using the correct region for this bucket?
Here I am confused how to put my region also I have created bucket name (spikessales) and I dont know how to give region as I am giving region which is present as aws browser url: look like:
https://s3.console.aws.amazon.com/s3/home?region=us-east-2
I am giving rgion which present at the end of this url (us-east-2) as u can see in my env file. And the region which I have created during creating bucket name is US East(N.Virginia). please tell me how to write region correctly.
Any help will be highly appreciated!