java在Amazon aws中不允许针对此资源使用指定的方法
伙计们,我可能是错的,也可能不是错的,但说真的,我正在努力解决AmazonS3存储桶中的文件上传问题。当我试图点击请求时,我得到了以下错误
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>
上面的消息是完整的消息,下面是我为上传文件到AmazonS3服务器而编写的代码
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;
}
请建议我怎么做?我将非常感谢你期望的答案
# 1 楼答案
您可能正在获取MethodNotAllowed,它建议使用属于bucket所有者帐户的标识
从S3API错误响应列表中