-
-
Save jhoanborges/b5eece139b53eb778ba4108bc430d9ed to your computer and use it in GitHub Desktop.
How to use Amazon S3 Presigned POSTs on Laravel + Vue JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use Aws\S3\PostObjectV4; | |
use Aws\S3\S3Client; | |
use Illuminate\Http\Request; | |
class ImageUploadController extends Controller | |
{ | |
public function createPreSignedPost() | |
{ | |
$client = new S3Client([ | |
'version' => 'latest', | |
'region' => 'ap-southeast-1', | |
'credentials' => ['key' => env('AWS_KEY'), 'secret' => env('AWS_SECRET'),], | |
]); | |
$bucket = env('AWS_BUCKET'); | |
$formInputs = ['acl' => 'public-read']; | |
$options = [['acl' => 'public-read'], ['bucket' => $bucket], ['starts-with', '$key', ''],]; | |
$expires = '+1 hours'; | |
$postObject = new PostObjectV4($client, $bucket, $formInputs, $options, $expires); | |
$formAttributes = $postObject->getFormAttributes(); | |
$formInputs = $postObject->getFormInputs(); | |
return response()->json(['code' => 200, 'formAttributes' => $formAttributes, 'formInputs' => $formInputs]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Route::get('create/pre-signed-url', 'ImageUploadController@createPreSignedPost'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment