Use to securely upload directly to a s3 bucket from your frontend. This package was designed to upload to s3 with Uppy but it could be used with other libraries.
Via Composer
composer require amish/laravel-s3-signed-route
Register the s3 signing route with the macro, then apply the middleware, etc. The route is registered with the name 's3-signed-route'.
Route::signedS3Route()->middleware(['auth', ...]);
let uppy = new Uppy({
allowMultipleUploads: false,
debug: true,
restrictions: {
allowedFileTypes: ['*'],
maxNumberOfFiles: 1,
minNumberOfFiles: 1,
},
}).use(AwsS3, {
getUploadParameters: (file) => {
// Send a request to our signing endpoint. route('s3-signed-route')
return fetch(signingEndpoint, {
method: 'post',
// Send and receive JSON.
headers: {
accept: 'application/json',
'content-type': 'application/json',
},
body: JSON.stringify({
filename: file.name,
contentType: file.type,
directory: 'uploads',
_token: document.querySelector('[name=csrf-token]').content,
}),
})
.then(response => response.json())
.then(data => {
// Return an object in the correct shape.
return {
method: data.method,
url: data.url,
fields: data.fields,
// Provide content type header required by S3
headers: {
'Content-Type': file.type,
},
}
})
},
});
Refer to Uppy's docs for more configuration options.
Please see contributing.md for details and a todolist.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
MIT. Please see the license file for more information.