amish / laravel-s3-signed-route
使用预签名路由从前端上传到s3。
v0.1.0
2022-06-13 23:23 UTC
Requires
- aws/aws-sdk-php: ^3.225.2
- illuminate/support: ~9
Requires (Dev)
- orchestra/testbench: ~7
- phpunit/phpunit: ~9.0
This package is auto-updated.
Last update: 2024-09-14 04:16:26 UTC
README
用于从前端安全地直接上传到s3存储桶。此包是为与Uppy一起使用而设计的,但也可用于其他库。
安装
通过Composer
composer require amish/laravel-s3-signed-route
使用方法
使用宏注册s3签名路由,然后应用中间件等。该路由以名称's3-signed-route'注册。
Route::signedS3Route()->middleware(['auth', ...]);
与Uppy一起使用
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, }, } }) }, });
有关更多配置选项,请参阅Uppy的文档。
贡献
有关详细信息,请参阅contributing.md以及待办事项清单。
安全
如果您发现任何与安全相关的问题,请通过author@email.com发送电子邮件,而不是使用问题跟踪器。
致谢
许可证
MIT。有关更多信息,请参阅许可证文件。