AWS HTTP 错误:cURL 错误 60:SSL 证书问题:无法获取本地颁发者证书

问题描述 投票:0回答:1

我正在尝试使用 Laravel 将我的头像上传到 backblaze 存储桶,但它抛出 SSL 证书问题错误,我已经配置了 filesystems.php 和 .env 文件:

这是 .env 文件配置:

BACKBLAZE_ACCOUNT_ID=005**************0003
BACKBLAZE_APP_KEY=K00******************VltI
BACKBLAZE_BUCKET=h**os
BACKBLAZE_BUCKET_ID=
BACKBLAZE_BUCKET_REGION=us-east-005

这是 filesystems.php:

'backblaze' => [
   'driver' => 's3',
   'key' => env('BACKBLAZE_ACCOUNT_ID'),
   'secret' => env('BACKBLAZE_APP_KEY'),
   'region' => env('BACKBLAZE_BUCKET_REGION'),
   'bucket' => env('BACKBLAZE_BUCKET'),
   'visibility' => 'public',
   'endpoint' => 'https://s3.'.env('BACKBLAZE_BUCKET_REGION').'.backblazeb2.com',
   'throw' => true,
],

这是我的代码:

public function uploadAvatar()
  {
    $validator = Validator::make($this->request->all(), [
      'avatar' => 'required|mimes:jpg,gif,png,jpe,jpeg|dimensions:min_width=200,min_height=200|max:' . $this->settings->file_size_allowed,
    ]);

    if ($validator->fails()) {
      return response()->json([
        'success' => false,
        'errors' => $validator->getMessageBag()->toArray(),
      ]);
    }

    $path = 'uploads/avatar/';

    if ($this->request->hasFile('avatar')) {
      $photo = $this->request->file('avatar');
      $extension = $photo->getClientOriginalExtension();
      $avatar = strtolower(auth()->user()->username . '-' . auth()->id() . time() . str_random(10) . '.' . $extension);

      $imgAvatar = Image::make($photo)->orientate()->fit(200, 200, function ($constraint) {
        $constraint->aspectRatio();
        $constraint->upsize();
      })->encode($extension);

      $uploaded = Storage::disk('backblaze')->put($path . $avatar, $imgAvatar);

      if ($uploaded) {
        Log::info('Avatar uploaded successfully: ' . $path . $avatar);

        if (auth()->user()->avatar != $this->settings->avatar) {
          Storage::disk('backblaze')->delete($path . auth()->user()->avatar);
        }

        // Update the user's avatar in the database
        auth()->user()->update(['avatar' => $avatar]);

        return response()->json([
          'success' => true,
          'avatar' => Storage::disk('backblaze')->url($path . $avatar),
        ]);
      } else {
        // If the upload fails
        Log::error('Failed to upload avatar: ' . $path . $avatar);

        return response()->json([
          'success' => false,
          'message' => 'Failed to upload avatar.',
        ]);
      }
    }

    return response()->json([
      'success' => false,
      'message' => 'No file uploaded',
    ]);
  }

这是错误:

[2024-08-21 01:38:53] local.ERROR: Unable to write file at location: uploads/avatar/lblanks-11724222331dzkxl8cyrp.png. Error executing "PutObject" on "https://s3.us-east-005.backblazeb2.com/hvideos/uploads/avatar/lblanks-11724222331dzkxl8cyrp.png"; AWS HTTP error: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://s3.us-east-005.backblazeb2.com/hvideos/uploads/avatar/lblanks-11724222331dzkxl8cyrp.png {"userId":1,"exception":"[object] (League\\Flysystem\\UnableToWriteFile(code: 0): Unable to write file at location: uploads/avatar/lblanks-11724222331dzkxl8cyrp.png. Error executing \"PutObject\" on \"https://s3.us-east-005.backblazeb2.com/hvideos/uploads/avatar/lblanks-11724222331dzkxl8cyrp.png\"; AWS HTTP error: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://s3.us-east-005.backblazeb2.com/hvideos/uploads/avatar/lblanks-11724222331dzkxl8cyrp.png at S:\\Freelancer\\version58trials\\version58trials\\vendor\\league\\flysystem\\src\\UnableToWriteFile.php:24)
[stacktrace]
#0 S:\\Freelancer\\version58trials\\version58trials\\vendor\\league\\flysystem-aws-s3-v3\\AwsS3V3Adapter.php(165): League\\Flysystem\\UnableToWriteFile::atLocation('uploads/avatar/...', 'Error executing...', Object(Aws\\S3\\Exception\\S3Exception))
#

我不知道如何解决这个 SSL 问题,我尝试在 filesystems.php 中添加这些行来禁用 SSL 验证,以首先检查它是否在本地主机上工作。

'backblaze' => [
   'driver' => 's3',
   'key' => env('BACKBLAZE_ACCOUNT_ID'),
   'secret' => env('BACKBLAZE_APP_KEY'),
   'region' => env('BACKBLAZE_BUCKET_REGION'),
   'bucket' => env('BACKBLAZE_BUCKET'),
   'visibility' => 'public',
   'endpoint' => 'https://s3.'.env('BACKBLAZE_BUCKET_REGION').'.backblazeb2.com',
   'throw' => true,
   // added following lines to disbale SSL verification
   'use_path_style_endpoint' => true, 
   'options' => [
               'scheme' => 'https',
                'http' => [
                    'verify' => false, // Disable SSL verification
                ],
            ],
],
laravel file-upload backblaze
1个回答
0
投票

所以我找到了答案,对于此类错误,解决方案在这里提出:

[https://stackoverflow.com/a/46516255/23020656][1]

© www.soinside.com 2019 - 2024. All rights reserved.