Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services Amazon S3 Bucket大文件上传_Amazon Web Services_Spring Boot_Amazon S3_Amazon Elastic Beanstalk - Fatal编程技术网

Amazon web services Amazon S3 Bucket大文件上传

Amazon web services Amazon S3 Bucket大文件上传,amazon-web-services,spring-boot,amazon-s3,amazon-elastic-beanstalk,Amazon Web Services,Spring Boot,Amazon S3,Amazon Elastic Beanstalk,我正在尝试使用JavaSDK将大约5MB大小的CSV文件上传到AmazonS3 我得到以下提到的错误: com.amazonaws.services.s3.model.amazons3异常:指定的 上载不存在。上载ID可能无效,或者上载失败 可能已中止或完成。(服务:Amazon S3;状态代码: 404;错误代码:NoSuchUpload;请求ID:) 你能告诉我出了什么问题吗。我正在使用us-west-1地区 List<PartETag> partETags = new

我正在尝试使用JavaSDK将大约5MB大小的CSV文件上传到AmazonS3

我得到以下提到的错误:

com.amazonaws.services.s3.model.amazons3异常:指定的 上载不存在。上载ID可能无效,或者上载失败 可能已中止或完成。(服务:Amazon S3;状态代码: 404;错误代码:NoSuchUpload;请求ID:)

你能告诉我出了什么问题吗。我正在使用
us-west-1
地区

    List<PartETag> partETags = new ArrayList<PartETag>();
    InitiateMultipartUploadRequest initRequest = new 
    InitiateMultipartUploadRequest(tempVariableBucketName, tempVariableAccessKey);
    InitiateMultipartUploadResult initResponse = s3Client.initiateMultipartUpload(initRequest);

    long contentLength = is.available();
    long partSize = 1 * 1024 * 1024; // Set part size to 1 MB.

    try {
        long filePosition = 0;
        for (int i = 1; filePosition < contentLength; i++) {
            partSize = Math.min(partSize, (contentLength - filePosition));
            logger.info("Upload Id " + initResponse.getUploadId());
            UploadPartRequest uploadRequest = new UploadPartRequest()
                .withBucketName(tempVariableBucketName).withKey(fileName)
                .withUploadId(initResponse.getUploadId()).withPartNumber(i)
                .withFileOffset(filePosition)
                .withInputStream(is)
                .withPartSize(partSize);

            partETags.add(s3Client.uploadPart(uploadRequest).getPartETag());
            filePosition += partSize;
        }
        CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest(tempVariableBucketName,tempVariableAccessKey,initResponse.getUploadId(),partETags);
        s3Client.completeMultipartUpload(compRequest);
    } catch (Exception e) {
        logger.error(e.getMessage());
        s3Client.abortMultipartUpload(new AbortMultipartUploadRequest(tempVariableBucketName, tempVariableAccessKey, initResponse.getUploadId()));
        throw e;
    }
List partETags=new ArrayList();
InitiateMultipartUploadRequest initRequest=新建
InitiateMultipartUploadRequest(tempVariableBucketName、tempVariableAccessKey);
InitiateMultipartUploadResult initResponse=s3Client.initiateMultipartUpload(initRequest);
long contentLength=is.available();
长零件尺寸=1*1024*1024;//将部件大小设置为1 MB。
试一试{
长文件位置=0;
for(inti=1;filePosition
请确保我们的AWS S3配置:
*
收到
3000
批准

您的一次上载失败。您需要从s3Client.uploadPart()捕获错误,然后重试

我建议对下面的简单代码进行以下改进

1) 为每次重试添加一个递增的超时

2) 处理错误类型以确定重试是否有意义。对于某些错误,您应该报告错误并中止

3) 将重试次数限制在10次左右,以防止出现永久while循环

// repeat the upload until it succeeds.
boolean anotherPass;  
    do {
          anotherPass = false;  // assume everythings ok
          try {
              // Upload part and add response to our list.
              partETags.add(s3Client.uploadPart(uploadRequest).getPartETag());
          } catch (Exception e) {
                anotherPass = true; // repeat
          }
    } while (anotherPass);
此堆栈溢出问题包含用于改进示例错误处理的代码


我通过使用AWS的GenerateDesign DurlRequest功能解决了这个问题。 但是现在我得到一个新错误。413请求实体太大nginx。我在谷歌上搜索了解决方案,发现我需要在服务器的nginx.conf文件中进行更改。
现在的问题是,由于我将拥有多个服务器/负载平衡器实例,因此,我是否必须为每个实例手动设置它?

谢谢Aman,但此配置已存在于“权限”选项卡下的CORS配置中。但是,它仍然不起作用。你能提供代码吗?我已经发布了代码。我之前已经浏览了你提到的链接。但是没有成功。每次我收到相同的错误时,指定的上载不存在。上载ID可能无效,或者上载可能已中止或完成。我需要对上传id做一些更改吗?我已经发布了代码。请检查一下好吗。我添加了重试被阻止并尝试了一次,但没有成功。每次重试时,我都会收到相同的错误消息Upload Id is invalid请使用集成的重试代码更新您的问题。还添加一个关于错误的打印语句,以便我们知道每个上载部件都会出现什么错误。您能否详细说明如何使用GeneratePresignedUrlRequest功能解决此问题?我也有同样的问题,似乎不知道如何使用该功能。
// repeat the upload until it succeeds.
boolean anotherPass;  
    do {
          anotherPass = false;  // assume everythings ok
          try {
              // Upload part and add response to our list.
              partETags.add(s3Client.uploadPart(uploadRequest).getPartETag());
          } catch (Exception e) {
                anotherPass = true; // repeat
          }
    } while (anotherPass);