use of com.aliyun.oss.model.InitiateMultipartUploadRequest in project aliyun-oss-java-sdk by aliyun.
the class ChunkedEncodingTest method testUploadPartChunked.
@Ignore
public void testUploadPartChunked() {
try {
InitiateMultipartUploadRequest initiateMultipartUploadRequest = new InitiateMultipartUploadRequest(bucketName, key);
InitiateMultipartUploadResult initiateMultipartUploadResult = client.initiateMultipartUpload(initiateMultipartUploadRequest);
String uploadId = initiateMultipartUploadResult.getUploadId();
File file = new File(filePath);
final int partSize = 5 * 1024 * 1024;
int fileSize = (int) file.length();
final int partCount = (file.length() % partSize != 0) ? (fileSize / partSize + 1) : (fileSize / partSize);
List<PartETag> partETags = new ArrayList<PartETag>();
for (int i = 0; i < partCount; i++) {
InputStream fin = new BufferedInputStream(new FileInputStream(file));
fin.skip(i * partSize);
int size = (i + 1 == partCount) ? (fileSize - i * partSize) : partSize;
UploadPartRequest req = new UploadPartRequest();
req.setBucketName(bucketName);
req.setKey(key);
req.setPartNumber(i + 1);
req.setPartSize(size);
req.setUploadId(uploadId);
req.setInputStream(fin);
req.setUseChunkEncoding(true);
UploadPartResult result = client.uploadPart(req);
partETags.add(result.getPartETag());
}
String expectedETag = calcMultipartETag(partETags);
CompleteMultipartUploadRequest completeMultipartUploadRequest = new CompleteMultipartUploadRequest(bucketName, key, uploadId, partETags);
CompleteMultipartUploadResult completeMultipartUploadResult = client.completeMultipartUpload(completeMultipartUploadRequest);
String actualETag = completeMultipartUploadResult.getETag();
Assert.assertEquals(expectedETag, actualETag);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.InitiateMultipartUploadRequest in project aliyun-oss-java-sdk by aliyun.
the class MultipartUploadSample method claimUploadId.
private static String claimUploadId() {
InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(bucketName, key);
InitiateMultipartUploadResult result = client.initiateMultipartUpload(request);
return result.getUploadId();
}
Aggregations