Upload files to AWS S3 Directly from Browser
- 1 Install the package via composer:
composer require hassan/laravel-s3-browser-based-uploads
- 2 Publish the config file of the package.
php artisan vendor:publish --provider="Hassan\S3BrowserBasedUploads\ServiceProvider" --tag=config
- 3 add your AWS settings
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=
AWS_BUCKET=
use Hassan\S3BrowserBasedUploads\Facades\S3BrowserBasedUploads;
S3BrowserBasedUploads::getEndpointUrl()
S3BrowserBasedUploads::getFields()
// with another connection
S3BrowserBasedUploads::connection('another')->getFields();
const formData = new FormData();
@foreach(S3BrowserBasedUploads::getFields() as $key => $value)
formData.append('{{ $key }}', '{{ $value }}');
@endforeach
formData.append('Content-Type', file.type);
formData.append('file', file, file.name);
const request = new XMLHttpRequest();
request.open('POST', "{{ S3BrowserBasedUploads::getEndpointUrl() }}");
request.send(formData);
Check out the demo with Filepond
Or Using Credentials Routes
// use Hassan\S3BrowserBasedUploads\S3BrowserBasedUploads;
public function boot()
{
S3BrowserBasedUploads::routes();
}
If you discover any security related issues, please email hello@hassan-ali.me instead of using the issue tracker.