尝试使用底层API。
当出现问题时,这将使您有更多的控制权,因为它们可能与11GB文件有关。
往返S3的请求有时会失败。使用低级API,如果上传失败,您将可以重试其中的一部分。
重构一下Amazon文档中的示例:
// Step 2: Upload parts.long filePosition = 0;for (int i = 1; filePosition < contentLength; i++) { // Last part can be less than 5 MB. Adjust part size. partSize = Math.min(partSize, (contentLength - filePosition)); // Create request to upload a part. UploadPartRequest uploadRequest = new UploadPartRequest() .withBucketName(existingBucketName).withKey(keyName) .withUploadId(initResponse.getUploadId()).withPartNumber(i) .withFileOffset(filePosition) .withFile(file) .withPartSize(partSize); // 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); filePosition += partSize;} // Step 3: complete. CompleteMultipartUploadRequest compRequest = newCompleteMultipartUploadRequest( existingBucketName,keyName,initResponse.getUploadId(),partETags); s3Client.completeMultipartUpload(compRequest);
注意:我不是Java开发人员,所以我可能会在语法上搞砸,但是希望这可以使您朝正确的方向前进。另外,如果上传反复失败,您将需要添加“重试计数器”以防止无限循环。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)