Amazon aws 中不允许针对此资源使用指定的方法

Pus*_*dra 5 java amazon-s3 amazon-web-services smartfoxserver

伙计们,我可能错了,也可能没有错,但说真的,我正在努力解决 Amazon S3 存储桶中的文件上传问题。当我尝试满足该请求时,我收到以下错误。

MethodNotAllowed不允许针对此资源指定方法

上面的消息是下面的响应的类型。

<?xml version="1.0" encoding="UTF-8"?><Error><Code>MethodNotAllowed</Code
<Message>Thespecified method is not allowed against this resource.</Message>
<Method>POST</Method><ResourceType>OBJECT</ResourceType>
<RequestId>xxx</RequestId><HostId>xxxx</HostId></Error>
Run Code Online (Sandbox Code Playgroud)

上面的消息是完整的消息,下面是我编写的用于将文件上传到亚马逊 s3 服务器的代码。

public synchronized boolean uploadFile(String url, String name, File file) {
    HttpEntity entity = MultipartEntityBuilder.create()
            .addPart("file", new FileBody(file)).build();
    HttpPost request = new HttpPost(url);
    request.setEntity(entity);
    HttpClient client = HttpClientBuilder.create().build();
    try {
        HttpResponse response = client.execute(request);
        entity = response.getEntity();
        if (entity != null) {
            try (InputStream in_stream = entity.getContent()) {
                BufferedReader in = new BufferedReader(new InputStreamReader(in_stream));
                String inputLine;
                StringBuilder responseBuffer = new StringBuilder();
                while ((inputLine = in.readLine()) != null) {
                    responseBuffer.append(inputLine);
                }
                in.close();
                String a = responseBuffer.toString();
                Utils.print("\n\n" + a + "\n\n");
            }
        }
        return true;
    } catch (Exception e) {
        Utils.print(e);
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

请建议我为此做什么?我将非常感谢您的预期答复。

小智 2

您可能会收到 MethodNotAllowed,它建议使用属于存储桶所有者帐户的身份。

如果您拥有正确的权限,但未使用属于存储桶所有者账户的身份,则 Amazon S3 将返回 405 方法不允许错误。 https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketPolicy.html

来自 S3 API 错误响应列表

不允许针对此资源使用指定的方法。
https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html