при загрузке изображения в корзину S3 через JS сообщение показывает ошибку отказа в доступе - PullRequest
0 голосов
/ 08 мая 2020
AWS.config.update({
  region: bucketRegion,

  credentials: new AWS.CognitoIdentityCredentials({
    IdentityPoolId: IdentityPoolId
  })
});
    function upload_image(id){
    var files = document.getElementById(id).files;
        if (!files.length) {
          return alert("Please choose a file to upload first.");
        }
        var file = files[0];
        var fileName = file.name;
        var albumPhotosKey = encodeURIComponent(albumBucketName) + "//";
        var photoKey = albumPhotosKey + fileName;

      // Use S3 ManagedUpload class as it supports multipart uploads
        var upload = new AWS.S3.ManagedUpload({
          params: {
            Bucket: albumBucketName,
            Key: photoKey,
            Body: file,
            ACL: "public-read"
          }
        });

      var promise = upload.promise();
      promise.then(
        function(data) {
          alert("Successfully uploaded photo.");
          viewAlbum(albumName);
        },
        function(err) {
          console.log(err)
          return alert("There was an error uploading your photo: ", err.message);
        }
      );}

при загрузке изображения в корзину S3 через JS сообщение показывает ошибку отказа в доступе. при ошибке консоли браузера ([HTTP / 1.1 403 Forbidden 2156ms]). все настройки ведра: publi c. **

1 Ответ

0 голосов
/ 09 мая 2020

Попробуйте добавить это в свое правило CORS в свою политику по адресу bucketname -> permissions -> CORS configuration

<CORSRule>
    <AllowedOrigin>localhost:3000</AllowedOrigin>
    <AllowedMethod>POST</AllowedMethod>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>PUT</AllowedMethod>
    <AllowedMethod>DELETE</AllowedMethod>
    <AllowedMethod>HEAD</AllowedMethod>
    <AllowedHeader>*</AllowedHeader>
</CORSRule>
...