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

标签 java amazon-web-services amazon-s3 smartfoxserver

伙计们,我可能错了,也可能没有错,但说真的,我正在努力解决 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/

相关文章:

java - 错误 "Cannot find symbol method charAt(int)"?

amazon-web-services - 如何在 Ubuntu 16.04 上安装 AWS SAM Local?

javascript - 使用带有 AWS S3 的签名请求并上传照片?

javascript - Node 和 s3 的正确凭据

java - 从二进制 png 图像检索的像素数据中检测矩形

java - Recordset 不适用于参数 (String[]) -- 接受多个参数时出错

java - 帮助在现有的 jsf 项目中创建 servlet

mysql - 如何在 AWS RDS 中将时区设置为 EST

ruby - 加载错误 : no such file to load -- openssl/dummy

php - Laravel 5.2 多个 file_get_contents() 不适用于产品