【问题标题】:How to generate md5 checksum for AWS S3 multi-part upload?如何为 AWS S3 分段上传生成 md5 校验和?
【发布时间】:2016-07-29 13:32:22
【问题描述】:

我已成功将多部分文件上传到 AWS S3,但现在我正尝试将 MD5 校验和添加到每个部分:

static void sendPart(existingBucketName, keyName, multipartRepsonse, partNum,
                     sendBuffer, partSize, vertx, partETags, s3, req, resultClosure)
{

    // Create request to upload a part.
    MessageDigest md = MessageDigest.getInstance("MD5")
    byte[] digest = md.digest(sendBuffer.bytes)
    println(digest.toString())
    InputStream inputStream = new ByteArrayInputStream(sendBuffer.bytes)
    UploadPartRequest uploadRequest = new UploadPartRequest()
        .withBucketName(existingBucketName).withKey(keyName)
        .withUploadId(multipartRepsonse.getUploadId()).withPartNumber(partNum)
        .withInputStream(inputStream)
        .withMD5Digest(Base64.getEncoder().encode(digest).toString())
        .withPartSize(partSize);

    // Upload part and add response to our list.
    vertx.executeBlocking({ future ->

            // Do the blocking operation in here

            // Imagine this was a call to a blocking API to get the result
            try {
                println("Sending chunk for ${keyName}")
                PartETag eTag = s3.uploadPart(uploadRequest).getPartETag()
                partETags.add(eTag);
                println("Etag: " + eTag.ETag)
                req.response().write("Sending Chunk\n")
            } catch(Exception e) {
            }

            def result = "success!"

            future.complete(result)
        }, resultClosure)
}

但是我收到以下错误:

AmazonS3Exception:您提供的 XML 格式不正确或没有 针对我们发布的架构进行验证(服务:Amazon S3;状态 代码:400;错误代码:MalformedXML;请求 ID:91542E819781FDFC),S3 扩展请求 ID: yQs45H/ozn5+xlxV9lRgCQWwv6gQysT6A4ablq7/Epq06pUzy0qGvMc+YAkJjo/RsHk2dedH+pI=

我做错了什么?

【问题讨论】:

    标签: amazon-web-services amazon-s3 multipart md5sum


    【解决方案1】:

    看来我的摘要转换不正确。

    static void sendPart(existingBucketName, keyName, multipartRepsonse, partNum,
                         sendBuffer, partSize, vertx, partETags, s3, req, resultClosure)
    {
    
        // Create request to upload a part.
        MessageDigest md = MessageDigest.getInstance("MD5")
        byte[] digest = md.digest(sendBuffer.bytes)
        InputStream inputStream = new ByteArrayInputStream(sendBuffer.bytes)
        UploadPartRequest uploadRequest = new UploadPartRequest()
            .withBucketName(existingBucketName).withKey(keyName)
            .withUploadId(multipartRepsonse.getUploadId()).withPartNumber(partNum)
            .withInputStream(inputStream)
            .withMD5Digest(Base64.getEncoder().encodeToString(digest))
            .withPartSize(partSize)
    
        // Upload part and add response to our list.
        vertx.executeBlocking({ future ->
    
                try {
                    println("Sending chunk for ${keyName}")
                    PartETag eTag = s3.uploadPart(uploadRequest).getPartETag()
                    partETags.add(eTag);
                    req.response().write("Sending Chunk\n")
                } catch(Exception e) {
                }
    
                def result = "success!"
    
                future.complete(result)
            }, resultClosure)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-04
      • 2018-09-07
      相关资源
      最近更新 更多