【问题标题】:Android Volley put file AWS S3 Signed requestAndroid Volley 将文件 AWS S3 签名请求
【发布时间】:2017-01-27 13:57:04
【问题描述】:

我正在尝试使用签名请求将文件上传到 android 中的 AWS S3。

我尝试实现this code,但出现错误403:

<Error>
    <Code>SignatureDoesNotMatch</Code>
    <Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
    <AWSAccessKeyId>xxx</AWSAccessKeyId>
    <StringToSign>PUT
      x-www-form-urlencoded; charset=UTF-8 <!-- Not wanted parameters -->
      expireTimeStamp
      /my-url
    </StringToSign>
    <SignatureProvided>xxx</SignatureProvided>
    <StringToSignBytes>xxx</StringToSignBytes>
    <RequestId>xxx</RequestId>
    <HostId>xxx</HostId>
</Error>

那么,如何从凌空请求中删除x-www-form-urlencoded; charset=UTF-8

【问题讨论】:

    标签: android amazon-s3 android-volley http-status-code-403


    【解决方案1】:

    简单地说:

    @Override
    public String getBodyContentType()
    {
        return "";
    }
    

    【讨论】:

    • 我在这个问题上失去了两天的生命......感谢您提供唯一有效的解决方案??‍♂️
    【解决方案2】:

    确保在标题中:

    内容类型

    和 在体内

    二进制数据:

    public static byte[] getBytes(Context context, Uri uri) {
        InputStream iStream = null;
        try {
            iStream = context.getContentResolver().openInputStream(uri);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        byte[] inputData = new byte[0];
        try {
            ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
            int bufferSize = 1024;
            byte[] buffer = new byte[bufferSize];
    
            int len;
            while ((len = iStream != null ? iStream.read(buffer) : 0) != -1) {
                byteBuffer.write(buffer, 0, len);
            }
            inputData = byteBuffer.toByteArray();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return inputData;
    
    }
    
    
    @Override
    public String getBodyContentType() {
         return null; 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-26
      • 1970-01-01
      • 2021-10-13
      • 2022-07-16
      • 1970-01-01
      • 2020-10-23
      • 2020-12-05
      • 2019-08-05
      相关资源
      最近更新 更多