为什么我会收到 AmazonS3Exception?

Why am I getting a AmazonS3Exception?

我的任务是加密上传到 S3 的文件。加密前上传工作正常,但现在我加密文件后出现此异常。

The XML you provided was not well-formed or did not validate against our published schema

我将其添加到现有代码

        final AwsCrypto crypto = new AwsCrypto();

        try (
            final FileInputStream in = new FileInputStream(encryptfile);
            final FileOutputStream out = new FileOutputStream(file);
            final CryptoOutputStream<?> encryptingStream = crypto.createEncryptingStream(crypt, out)) 
        {
            IOUtils.copy(in, encryptingStream);
        }


我的想法,为什么 AmazonS3 需要一个 XML-File ?为什么不是普通的文本文档?
是否可以通过存储桶策略更改此选项?

编辑
那是上传代码,可能有问题。我不明白为什么它在没有加密的情况下工作。

             File uploaffile = encryptFile(file);
             List<PartETag> partETags = new ArrayList<PartETag>();
             String filename = String.valueOf(System.currentTimeMillis());

             InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(awss3bucket, filename);
             InitiateMultipartUploadResult initResponse = amazons3.initiateMultipartUpload(initRequest);
             long partSize = 5 * 1024 * 1024; 
             long contentLength = uploaffile.length();
             long filePosition = 0;
             for (int i = 1; filePosition < contentLength; i++) {
                 partSize = Math.min(partSize, (contentLength - filePosition));

                 UploadPartRequest uploadRequest = new UploadPartRequest()
                         .withBucketName(awss3bucket)
                         .withKey(filename)
                         .withUploadId(initResponse.getUploadId())
                         .withPartNumber(i)
                         .withFileOffset(filePosition)
                         .withFile(uploaffile)
                         .withPartSize(partSize);

                 PartETag petag = new PartETag(amazons3.uploadPart(uploadRequest).getPartNumber(), amazons3.uploadPart(uploadRequest).getETag());
                 partETags.add(petag);

                 filePosition += partSize;
             }

             CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest(awss3bucket, filename,
                                                                                            initResponse.getUploadId(), partETags);

             amazons3.completeMultipartUpload(compRequest);

也许下次我应该停止从 Internet 上复制一些随机代码。
您使用 FileoutputStream 来写而不是其他方式。所以文件是空的,这导致了异常。

        CryptoInputStream<KmsMasterKey> encryptingStream = crypto.createEncryptingStream(crypt, in);
        FileOutputStream out = null;

        try {
            out = new FileOutputStream(encryptfile);
            IOUtils.copy(encryptingStream, out);
            encryptingStream.close();
            out.close();
        } catch (IOException e)