php - 文件上传不会在 AWS S3 中被覆盖
问题描述
我想上传一个 excel 文件,但 AWS 没有保存我的文件。我不知道问题是什么。我尝试转储所有数据,并且该过程说它已成功上传。
下面是我的代码和涉及 laravel 的文件:
文件夹库.php
public static function upload($name, $path, $file)
{
$path = preg_replace('{/$}', '', $path);
$original_path = $path;
//add tenant folder as parent folder
$path = 'prod/' . config('b3.tenant_path') . '/' . $path;
//check folder to separete public and private bucket
$private_folder = ['student', 'finance', 'images', 'user', 'oa_material', 'active-student'];
if (array_intersect(explode('/', $path), $private_folder)) {
$s3_access = 's3_private';
} else {
$s3_access = 's3_public';
}
if (pathinfo($name, PATHINFO_EXTENSION) == "") {
$extension = $file->getClientOriginalExtension(); // getting file extension
$fileName = $name . '.' . $extension;
} else {
$fileName = $name;
}
$full_path = $path . '/' . $fileName;
if (is_string($file)) {
//$upload_path = Storage::disk(config('b3.disk'))->put($full_path, $file);
$upload_path = Storage::disk($s3_access)->put($full_path, $file);
} else {
// $upload_path = Storage::disk($s3_access)->putFileAs($path, $file, $fileName);
$upload_path = Storage::disk($s3_access)->put($path, $file);
}
$data['name'] = $fileName;
$data['path'] = $original_path . '/' . $fileName;
return $data;
}
文件系统.php
'disks' => [
's3_public' => [
'driver' => 's3',
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET_PUB'),
'url' => env('AWS_URL'),
'visibility' => 'public'
],
's3_private' => [
'driver' => 's3',
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET_PRI'),
'url' => env('AWS_URL'),
'visibility' => 'private'
],
],
ImportLeadController.php
public function store()
{
$data = [];
$file_name = 'temp-import-prospect-file-' . auth()->user()->id;
$file_info = FileFolderLibrary::upload($file_name, 'marketing/import_prospect', Input::file('file'));
$excel = Excel::load(Input::file('file'), function ($reader) {
$reader->formatDates(true, GeneralSetting::where('field', 'system_date_format')->select(['value'])->first()->value);
return $reader;
});
$result = $excel->get();
$result = $this->convertData($result);
$data = [];
$data['prospects'] = $result;
$data['file_name'] = $file_info['name'];
return $data;
}
.env
AWS_BUCKET_PUB=vialing-image-public
AWS_BUCKET_PRI=vialing-image-private
AWS_REGION=ap-southeast-1
AWS_URL=https://cdn1.vialing.com/
谁能知道如何克服这个问题?谢谢你。
解决方案
推荐阅读
- java - 如何将arraylist方法用于另一种方法?
- javascript - 无法从 DOM 中的 datalist 对象访问列表属性
- azure-devops - Azure DevOps 拉取请求行颜色
- sharepoint - SharePoint 计时器作业在密码更改后停止工作
- google-apps-script - 将变量内容添加到 HTML 模板中的文本区域
- javascript - 如何在 React js 中获取开始日期和当前月份的日期?
- javascript - 在不刷新页面的情况下更改 URl NEXT.JS
- javascript - 解析充满字符串的对象时 JSON 解析出现 CORS 错误
- segmentation-fault - 链表实现中的分段错误,同时找到它的中间
- zerobrane - 在 zerobrane 的交互式解释器中,math.maxinteger 值为零