简体   繁体   English

如何为AWS S3分段上传生成md5校验和?

[英]How to generate md5 checksum for AWS S3 multi-part upload?

I am successfully uploading multi-part files to AWS S3, but now I'm attempting to ad an MD5 checksum to each part: 我已成功将多部分文件上传到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)
}

However I get the following error: 但是我收到以下错误:

AmazonS3Exception: The XML you provided was not well-formed or did not validate against our published schema (Service: Amazon S3; Status Code: 400; Error Code: MalformedXML; Request ID: 91542E819781FDFC), S3 Extended Request ID: yQs45H/ozn5+xlxV9lRgCQWwv6gQysT6A4ablq7/Epq06pUzy0qGvMc+YAkJjo/RsHk2dedH+pI= AmazonS3Exception:您提供的XML格式不正确或未针对我们发布的架构进行验证(服务:Amazon S3;状态代码:400;错误代码:MalformedXML;请求ID:91542E819781FDFC),S3扩展请求ID:yQs45H / ozn5 + xlxV9lRgCQWwv6gQysT6A4ablq7 / Epq06pUzy0qGvMc + YAkJjo / RsHk2dedH + pI =

What am I doing incorrectly? 我做错了什么?

Looks like I was converting the digest incorrectly. 看来我没有正确转换摘要。

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)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不共享密钥的情况下执行 AWS S3 分段上传 - How to perform AWS S3 multi-part upload without sharing secret keys 使用适用于 JavaScript 的 AWS 开发工具包 v3 完成多部分上传到 S3 的 XML 错误 - XML error completing a multi-part upload to S3 with AWS SDK for JavaScript v3 AWS S3 多部分无法恢复 - AWS S3 Multi-Part Unable to resume Java AWS s3:如何使用Md5预签名URL设置和上传内容 - Java AWS s3: How to set and upload content with Md5 pre signed url 进度信息和异步Amazon S3分段上传的PartNumber - progress information and PartNumber of async Amazon S3 multi-part upload AWS SDK iOS 2.0 S3上传:添加正确的md5 - AWS SDK iOS 2.0 S3 upload: add correct md5 使用aws js sdk,无需使用cognito,即可将浏览器中的大文件(> 10GB)直接从浏览器安全地分段上传到s3 - Secure multi-part Upload of large files(>10GB) directly from browser to s3 using aws js sdk without using cognito 尝试使用 AWS Java v2 SDK 完成分段上传时出现 S3Exception - S3Exception when trying to complete multi-part upload using the AWS Java v2 SDK 使用 CLI 进行 Amazon AWS Glacier 分段上传 - Amazon AWS Glacier multi-part upload with CLI 为什么不支持在iOS上执行多部分上传到S3? - Why is Performing Multi-part Uploads to S3 on iOS not supported?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM