sudo程序员 / s3文件上传器
该软件包简化了在多个系统上处理Amazon S3上文件的难度。您可以通过提供存储桶详情和文件名来上传文件、在存储桶之间复制文件、检查文件是否存在以及下载文件。简单文件管理,实现流畅数据处理。
v1.0.0
2024-02-22 12:51 UTC
Requires
- aws/aws-sdk-php: ^3.300
README
介绍
此Laravel软件包简化了您应用程序在Amazon S3上的文件管理。它提供了上传、在存储桶之间复制、检查文件存在性和轻松下载文件的功能。
安装
使用Composer安装此软件包
composer require sudocoder/s3fileuploader
配置
在您的Laravel项目.env文件中设置以下环境变量
AWS_ACCESS_KEY_ID= //Your AWS Access Key ID.
AWS_SECRET_ACCESS_KEY= //Your AWS Secret Access Key.
AWS_DEFAULT_REGION= //The AWS region, e.g., us-east-1.
AWS_UPLOAD_BUCKET= //Target bucket for file uploads.
AWS_DESTINATION_BUCKET= //Destination bucket for file copying.
AWS_SOURCE_BUCKET= //Source bucket for file operations.
AWS_SOURCE_FOLDER= //Source folder for operations involving folders.
AWS_DESTINATION_FOLDER= //Destination folder for copying files.
AWS_UPLOAD_FILE_FOLDER= //Folder for uploading files.
APP_UPLOAD_IMAGE_FOLDER= //Folder for application-specific file uploads.
AWS_USE_PATH_STYLE_ENDPOINT= //Set to true if using a path-style S3 endpoint, otherwise false.
用法
上传文件
要将文件上传到S3,请使用以下命令
use SudoCoder\S3\S3FileUploader;
// Specify the file path and destination bucket
S3FileUploader::upload('local/path/to/file.txt');
在存储桶之间复制文件
要从一个存储桶复制文件到另一个存储桶
use SudoCoder\S3\S3FileUploader;
// Specify the file name and source/destination buckets and folder if any in env file
S3FileUploader::copyFile('file.txt');
检查文件存在性
要检查S3上的文件是否存在
use SudoCoder\S3\S3FileUploader;
// Specify the file name and the bucket
if (S3FileUploader::fileExists('file.txt', 'AWS_SOURCE_BUCKET', 'AWS_SOURCE_BUCKET_FOLDER')) {
// File exists
} else {
// File does not exist
}
下载文件
从S3下载文件
use SudoCoder\S3\S3FileUploader;
// Specify the file name and the bucket
S3FileUploader::download('file.txt', 'AWS_SOURCE_BUCKET', 'AWS_SOURCE_BUCKET_FOLDER');
贡献
请随意通过创建问题或提交拉取请求来为此软件包做出贡献。
许可
此软件包是开源的,可在MIT许可证下使用。