阿里云OSS上传报错: You have no right to access this object because of bucket acl

报错信息

com.aliyun.oss.OSSException: You have no right to access this object because of bucket acl.

[ErrorCode]: AccessDenied
[RequestId]: xxxxx
[HostId]: xxx.oss-cn-xxx.aliyuncs.com
[ResponseError]:


  AccessDenied
  You have no right to access this object because of bucket acl.
  xxxxx
  xxx.oss-cn-xxx.aliyuncs.com


at com.aliyun.oss.common.utils.ExceptionFactory.createOSSException(ExceptionFactory.java:100)
	at com.aliyun.oss.internal.OSSErrorResponseHandler.handle(OSSErrorResponseHandler.java:70)
	at com.aliyun.oss.common.comm.ServiceClient.handleResponse(ServiceClient.java:257)
	at com.aliyun.oss.common.comm.ServiceClient.sendRequestImpl(ServiceClient.java:140)
	at com.aliyun.oss.common.comm.ServiceClient.sendRequest(ServiceClient.java:70)
	at com.aliyun.oss.internal.OSSOperation.send(OSSOperation.java:83)
	at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:145)
	at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:102)
	at com.aliyun.oss.internal.OSSObjectOperation.writeObjectInternal(OSSObjectOperation.java:1125)
	at com.aliyun.oss.internal.OSSObjectOperation.putObject(OSSObjectOperation.java:130)
	at com.aliyun.oss.OSSClient.putObject(OSSClient.java:491)
	at com.aliyun.oss.OSSClient.putObject(OSSClient.java:475)
	

解决方法

首先确认你的 AccessKey 和 AccessKeySecret是否正确:
阿里云OSS上传报错: You have no right to access this object because of bucket acl_第1张图片

如果上面是对的,那就是OSS权限问题了:
你用的 AccessKey 对应的用户没有 OSS 权限,需要增加 OSS 权限:访问控制 -> 用户 -> 权限管理 -> 添加权限

  1. 点击侧边栏菜单进入 “访问控制”
    如果没有,可以通过右边的搜索框查询
    阿里云OSS上传报错: You have no right to access this object because of bucket acl_第2张图片

  2. 进入“用户”菜单
    阿里云OSS上传报错: You have no right to access this object because of bucket acl_第3张图片

  3. 添加权限
    从你的用户点进去,给该用户添加 OSS 权限
    阿里云OSS上传报错: You have no right to access this object because of bucket acl_第4张图片
    添加这个权限即可:AliyunOSSFullAccess 这是OSS的所有权限(最大权限)。
    阿里云OSS上传报错: You have no right to access this object because of bucket acl_第5张图片

自定义权限

如果你的 OSS 做了精细权限控制,那么需要自定义权限策略。

比如需要控制该用户只能访问 my-test 这个 bucket

  1. 先定义一个权限策略:oss-controller-test
    阿里云OSS上传报错: You have no right to access this object because of bucket acl_第6张图片
    策略脚本如下:

    {
        "Version": "1",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": "oss:*",
                "Resource": [
                    "acs:oss:*:*:my-test",
                    "acs:oss:*:*:my-test/*"
                ]
            }
        ]
    }
    
  2. 给用户添加“自定义权限“:oss-controller-test
    阿里云OSS上传报错: You have no right to access this object because of bucket acl_第7张图片

你可能感兴趣的:(阿里云,阿里云,oss)