Guys I may or may not be wrong, But seriously, I am struggling with file uploading problem in Amazon S3 bucket. When I am trying to hit on the request then I am getting the following error.
MethodNotAllowed and The specified method is not allowed against this resource
The above message is the sort of the below response.
<?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>
The above message is the complete message and below is the code whatever I have written for uploading files to amazon s3 server.
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;
}
Please suggest me what to do for this? I will be very thankful for your expected answer.