Skip to content

dhassanali/laravel-s3-browser-based-uploads

Repository files navigation

Laravel S3 Browser Based Uploads

Latest Version on Packagist Build Status Total Downloads License

Upload files to AWS S3 Directly from Browser

Installation

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

Usage

use Hassan\S3BrowserBasedUploads\Facades\S3BrowserBasedUploads;

S3BrowserBasedUploads::getEndpointUrl()

S3BrowserBasedUploads::getFields()

// with another connection
S3BrowserBasedUploads::connection('another')->getFields();

Example

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();
}

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.