AWS S3上传401未经授权

时间:2020-08-20 04:11:52

标签: amazon-s3

我正在尝试将图像上传到我的laravel应用程序中的aws s3上,但由于错误异常,我在listObjects上获得了未经授权的401。

我像这样设置存储桶策略:

{
"Version": "2012-10-17",
"Statement": [
    {
        "Action": [
            "s3:*"
        ],
        "Resource": [
            "arn:aws:s3:::bucketName",
            "arn:aws:s3:::bucketName/*"
        ],
        "Effect": "Allow",
        "Principal": "*"
    }
]
}

我在这里做错了什么?我只需要能够通过我们的应用程序上传图像

消息:#message: "Error executing "ListObjects" on "https://jfi.s3.amazonaws.com/?prefix=component_images%2F50000213.png%2F&max-keys=1&encoding-type=url"; AWS HTTP error: Client error: `GET https://testSite.s3.amazonaws.com/?prefix=component_images%2F50000213.png%2F&max-keys=1&encoding-type=url` resulted in a `401 Unauthorized` response (client): 401 Unauthorized - " #code: 0 #file: "C:\Users\testUser\testSite\vendor\aws\aws-sdk-php\src\WrappedHttpHandler.php"

堆栈跟踪:

    95. Aws\WrappedHttpHandler->parseError() ==> new Aws\S3\Exception\S3Exception(): {▶}
    94. Aws\WrappedHttpHandler->Aws\{closure}() ==> Aws\WrappedHttpHandler->parseError(): {▶}
    93. GuzzleHttp\Promise\Promise::callHandler() ==> Aws\WrappedHttpHandler->Aws\{closure}(): {▶}
    92. GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}() ==> GuzzleHttp\Promise\Promise::callHandler(): {▶}
    91. GuzzleHttp\Promise\RejectedPromise::GuzzleHttp\Promise\{closure}() ==> GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}(): {▶}
    90. GuzzleHttp\Promise\TaskQueue->run() ==> GuzzleHttp\Promise\RejectedPromise::GuzzleHttp\Promise\{closure}(): {▶}
    89. GuzzleHttp\Handler\CurlMultiHandler->tick() ==> GuzzleHttp\Promise\TaskQueue->run(): {▶}
    88. GuzzleHttp\Handler\CurlMultiHandler->execute() ==> GuzzleHttp\Handler\CurlMultiHandler->tick(): {▶}
    87. GuzzleHttp\Promise\Promise->invokeWaitFn() ==> GuzzleHttp\Handler\CurlMultiHandler->execute(): {▶}
    86. GuzzleHttp\Promise\Promise->waitIfPending() ==> GuzzleHttp\Promise\Promise->invokeWaitFn(): {▶}
    85. GuzzleHttp\Promise\Promise->invokeWaitList() ==> GuzzleHttp\Promise\Promise->waitIfPending(): {▶}
    84. GuzzleHttp\Promise\Promise->waitIfPending() ==> GuzzleHttp\Promise\Promise->invokeWaitList(): {▶}
    83. GuzzleHttp\Promise\Promise->invokeWaitList() ==> GuzzleHttp\Promise\Promise->waitIfPending(): {▶}
    82. GuzzleHttp\Promise\Promise->waitIfPending() ==> GuzzleHttp\Promise\Promise->invokeWaitList(): {▶}
    81. GuzzleHttp\Promise\Promise->wait() ==> GuzzleHttp\Promise\Promise->waitIfPending(): {▶}
    80. Aws\AwsClient->execute() ==> GuzzleHttp\Promise\Promise->wait(): {▶}
    79. League\Flysystem\AwsS3v3\AwsS3Adapter->doesDirectoryExist() ==> Aws\AwsClient->execute(): {▶}
    78. League\Flysystem\AwsS3v3\AwsS3Adapter->has() ==> League\Flysystem\AwsS3v3\AwsS3Adapter->doesDirectoryExist(): {▶}
    77. League\Flysystem\Filesystem->has() ==> League\Flysystem\AwsS3v3\AwsS3Adapter->has(): {▶}
    76. League\Flysystem\Filesystem->put() ==> League\Flysystem\Filesystem->has(): {▶}
    75. Illuminate\Filesystem\FilesystemAdapter->put() ==> League\Flysystem\Filesystem->put(): {▶}
    74. App\Http\Controllers\Product\RepairPartsController->uploadComponentImage() ==> Illuminate\Filesystem\FilesystemAdapter->put(): {▶}
    73. call_user_func_array() ==> App\Http\Controllers\Product\RepairPartsController->uploadComponentImage(): {▶}
    72. Illuminate\Routing\Controller->callAction() ==> call_user_func_array(): {▶}
    71. Illuminate\Routing\ControllerDispatcher->call() ==> Illuminate\Routing\Controller->callAction(): {▶}
    70. Illuminate\Routing\ControllerDispatcher->Illuminate\Routing\{closure}() ==> Illuminate\Routing\ControllerDispatcher->call(): {▶}
    69. call_user_func() ==> Illuminate\Routing\ControllerDispatcher->Illuminate\Routing\{closure}(): {▶}
    68. Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}() ==> call_user_func(): {▶}
    67. call_user_func() ==> Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(): {▶}
    66. Illuminate\Pipeline\Pipeline->then() ==> call_user_func(): {▶}
    65. Illuminate\Routing\ControllerDispatcher->callWithinStack() ==> Illuminate\Pipeline\Pipeline->then(): {▶}
    64. Illuminate\Routing\ControllerDispatcher->dispatch() ==> Illuminate\Routing\ControllerDispatcher->callWithinStack(): {▶}
    63. Illuminate\Routing\Route->runController() ==> Illuminate\Routing\ControllerDispatcher->dispatch(): {▶}
    62. Illuminate\Routing\Route->run() ==> Illuminate\Routing\Route->runController(): {▶}
    61. Illuminate\Routing\Router->Illuminate\Routing\{closure}() ==> Illuminate\Routing\Route->run(): {▶}
    60. call_user_func() ==> Illuminate\Routing\Router->Illuminate\Routing\{closure}(): {▶}
    59. Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}() ==> call_user_func(): {▶}
    58. App\Http\Middleware\GateChecker->handle() ==> Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(): {▶}
    57. call_user_func_array() ==> App\Http\Middleware\GateChecker->handle(): {▶}
    56. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() ==> call_user_func_array(): {▶}
    55. call_user_func() ==> Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(): {▶}
    54. Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}() ==> call_user_func(): {▶}
    53. App\Http\Middleware\Authenticate->handle() ==> Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(): {▶}
    52. call_user_func_array() ==> App\Http\Middleware\Authenticate->handle(): {▶}
    51. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() ==> call_user_func_array(): {▶}
    50. call_user_func() ==> Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(): {▶}
    49. Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}() ==> call_user_func(): {▶}
    48. App\Http\Middleware\LogEventUser->handle() ==> Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(): {▶}
    47. call_user_func_array() ==> App\Http\Middleware\LogEventUser->handle(): {▶}
    46. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() ==> call_user_func_array(): {▶}
    45. call_user_func() ==> Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(): {▶}
    44. Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}() ==> call_user_func(): {▶}
    43. Illuminate\View\Middleware\ShareErrorsFromSession->handle() ==> Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(): {▶}
    42. call_user_func_array() ==> Illuminate\View\Middleware\ShareErrorsFromSession->handle(): {▶}
    41. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() ==> call_user_func_array(): {▶}
    40. call_user_func() ==> Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(): {▶}
    39. Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}() ==> call_user_func(): {▶}
    38. Illuminate\Session\Middleware\StartSession->handle() ==> Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(): {▶}
    37. call_user_func_array() ==> Illuminate\Session\Middleware\StartSession->handle(): {▶}
    36. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() ==> call_user_func_array(): {▶}
    35. call_user_func() ==> Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(): {▶}
    34. Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}() ==> call_user_func(): {▶}
    33. Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle() ==> Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(): {▶}
    32. call_user_func_array() ==> Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(): {▶}
    31. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() ==> call_user_func_array(): {▶}
    30. call_user_func() ==> Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(): {▶}
    29. Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}() ==> call_user_func(): {▶}
    28. Illuminate\Cookie\Middleware\EncryptCookies->handle() ==> Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(): {▶}
    27. call_user_func_array() ==> Illuminate\Cookie\Middleware\EncryptCookies->handle(): {▶}
    26. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() ==> call_user_func_array(): {▶}
    25. call_user_func() ==> Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(): {▶}
    24. Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}() ==> call_user_func(): {▶}
    23. call_user_func() ==> Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(): {▶}
    22. Illuminate\Pipeline\Pipeline->then() ==> call_user_func(): {▶}
    21. Illuminate\Routing\Router->runRouteWithinStack() ==> Illuminate\Pipeline\Pipeline->then(): {▶}
    20. Illuminate\Routing\Router->dispatchToRoute() ==> Illuminate\Routing\Router->runRouteWithinStack(): {▶}
    19. Illuminate\Routing\Router->dispatch() ==> Illuminate\Routing\Router->dispatchToRoute(): {▶}
    18. Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}() ==> Illuminate\Routing\Router->dispatch(): {▶}
    17. call_user_func() ==> Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(): {▶}
    16. Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}() ==> call_user_func(): {▶}
    15. Barryvdh\Debugbar\Middleware\Debugbar->handle() ==> Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(): {▶}
    14. call_user_func_array() ==> Barryvdh\Debugbar\Middleware\Debugbar->handle(): {▶}
    13. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() ==> call_user_func_array(): {▶}
    12. call_user_func() ==> Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(): {▶}
    11. Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}() ==> call_user_func(): {▶}
    10. Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle() ==> Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(): {▶}
    9. call_user_func_array() ==> Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(): {▶}
    8. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() ==> call_user_func_array(): {▶}
    7. call_user_func() ==> Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(): {▶}
    6. Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}() ==> call_user_func(): {▶}
    5. call_user_func() ==> Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(): {▶}
    4. Illuminate\Pipeline\Pipeline->then() ==> call_user_func(): {▶}
    3. Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter() ==> Illuminate\Pipeline\Pipeline->then(): {▶}
    2. Illuminate\Foundation\Http\Kernel->handle() ==> Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(): {▶}
    1. {main} ==> Illuminate\Foundation\Http\Kernel->handle(): {▶}
  }```

1 个答案:

答案 0 :(得分:1)

添加CORS配置

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>POST</AllowedMethod>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>PUT</AllowedMethod>
    <AllowedMethod>DELETE</AllowedMethod>
    <AllowedMethod>HEAD</AllowedMethod>
    <AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>

希望如此。