gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 20:22:52 25 4
gpt4 key购买 nike

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

MethodNotAllowed and The specified method is not allowed against this resource

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

<?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>

上面的消息是完整的消息,下面是我编写的用于将文件上传到亚马逊 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;
}

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

最佳答案

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

If you have the correct permissions, but you're not using an identity that belongs to the bucket owner's account, Amazon S3 returns a 405 Method Not Allowed error. https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketPolicy.html

来自 S3 API 错误响应列表

The specified method is not allowed against this resource.
https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html

关于java - Amazon aws 中不允许针对此资源使用指定的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58928161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com