当前位置: 首页>>代码示例>>Java>>正文


Java InitiateMultipartUploadResult.getUploadId方法代码示例

本文整理汇总了Java中com.aliyun.oss.model.InitiateMultipartUploadResult.getUploadId方法的典型用法代码示例。如果您正苦于以下问题:Java InitiateMultipartUploadResult.getUploadId方法的具体用法?Java InitiateMultipartUploadResult.getUploadId怎么用?Java InitiateMultipartUploadResult.getUploadId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.aliyun.oss.model.InitiateMultipartUploadResult的用法示例。


在下文中一共展示了InitiateMultipartUploadResult.getUploadId方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initiateMultipartPut

import com.aliyun.oss.model.InitiateMultipartUploadResult; //导入方法依赖的package包/类
@Override
public CCSInitiateMultipartPutResponse initiateMultipartPut(
		CCSInitiateMultipartPutRequestable ccsInitiateMultipartPutRequestable) {
	InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(
			ccsInitiateMultipartPutRequestable.getBucketName(),
			ccsInitiateMultipartPutRequestable.getCcsObjectPath());
	InitiateMultipartUploadResult result = ossClient.initiateMultipartUpload(request);
	System.out.println(JSON.toJSONString(result));
	return new CCSInitiateMultipartPutResponse(result.getBucketName(), result.getKey(), result.getUploadId());
}
 
开发者ID:MinsxCloud,项目名称:minsx-ccs,代码行数:11,代码来源:AliyunOSSImpl.java

示例2: multipartUpload

import com.aliyun.oss.model.InitiateMultipartUploadResult; //导入方法依赖的package包/类
@Test
public  void multipartUpload() throws FileNotFoundException {
	InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest("minsx-bucket", "A.docx");
	InitiateMultipartUploadResult result = ossClient.initiateMultipartUpload(request);
	String uploadId = result.getUploadId();
	
	List<PartETag> partETags = new ArrayList<PartETag>();
	
	File file = new File("E:\\Temp\\A.docx");
	for (int i = 0; i < file.length(); i+=100 * 1024) {
		InputStream instream = new FileInputStream(file);
		UploadPartRequest uploadPartRequest = new UploadPartRequest();
		uploadPartRequest.setBucketName("minsx-bucket");
		uploadPartRequest.setKey("A.docx");
		uploadPartRequest.setUploadId(uploadId);
		uploadPartRequest.setInputStream(instream);
		uploadPartRequest.setPartSize(100 * 1024);
		uploadPartRequest.setPartNumber(i/(100 * 1024)+1);
		UploadPartResult uploadPartResult = ossClient.uploadPart(uploadPartRequest);
		partETags.add(uploadPartResult.getPartETag());
	}

	Collections.sort(partETags, new Comparator<PartETag>() {
	    @Override
	    public int compare(PartETag p1, PartETag p2) {
	        return p1.getPartNumber() - p2.getPartNumber();
	    }
	});
	CompleteMultipartUploadRequest completeMultipartUploadRequest = 
	        new CompleteMultipartUploadRequest("minsx-bucket", "A.docx", uploadId, partETags);
	ossClient.completeMultipartUpload(completeMultipartUploadRequest);
}
 
开发者ID:MinsxCloud,项目名称:minsx-ccs,代码行数:33,代码来源:OSSTest.java

示例3: doMultiPartCopy

import com.aliyun.oss.model.InitiateMultipartUploadResult; //导入方法依赖的package包/类
private CopyObjectResult doMultiPartCopy(CopyObjectRequest copyObjectRequest, ObjectMetadata metadata) {

    //Claim a new upload id for your target bucket
    InitiateMultipartUploadRequest initiateMultipartUploadRequest =
            new InitiateMultipartUploadRequest(copyObjectRequest.getDestinationBucketName(), copyObjectRequest.getDestinationKey());
    InitiateMultipartUploadResult initiateMultipartUploadResult = this.initiateMultipartUpload(initiateMultipartUploadRequest);
    String uploadId = initiateMultipartUploadResult.getUploadId();

    //Calculate how many parts to be divided
    long optimalPartSize = calculateOptimalPartSizeForCopy(configuration, metadata.getContentLength());
    long objectSize = metadata.getContentLength();
    int totalParts = (int) Math.ceil((double) objectSize / optimalPartSize);

    //Upload multi-parts by copy mode
    System.out.println("Begin to upload multiparts by copy mode to OSS\n");
    List<Future<PartETag>> futures = new ArrayList<Future<PartETag>>();
    for (int i = 0; i < totalParts; i++) {
      long startPos = i * optimalPartSize;
      long curPartSize = (i + 1 == totalParts) ? (objectSize - startPos) : optimalPartSize;

      //Construct UploadPartCopyRequest
      UploadPartCopyRequest uploadPartCopyRequest = new UploadPartCopyRequest(
              copyObjectRequest.getSourceBucketName(), copyObjectRequest.getSourceKey(), copyObjectRequest.getDestinationBucketName(), copyObjectRequest.getDestinationKey());
      uploadPartCopyRequest.setUploadId(uploadId);
      uploadPartCopyRequest.setPartSize(curPartSize);
      uploadPartCopyRequest.setBeginIndex(startPos);
      uploadPartCopyRequest.setPartNumber(i + 1);
      futures.add(threadPoolExecutor.submit(new PartCopyCallable(uploadPartCopyRequest)));
    }

    List<PartETag> partETags = collectPartETags(futures);
    //Verify whether all parts are finished
    if (partETags.size() != totalParts) {
      throw new IllegalStateException("Upload multi-parts fail due to some parts are not finished yet");
    } else {
      LOG.info("Succeed to complete multi-parts copy from object named {} to {}", copyObjectRequest.getSourceKey(), copyObjectRequest.getDestinationKey());
    }

    //Complete to upload multi-parts
    System.out.println("Completing to upload multiparts\n");
    CompleteMultipartUploadRequest completeMultipartUploadRequest = new CompleteMultipartUploadRequest(
            copyObjectRequest.getDestinationBucketName(), copyObjectRequest.getDestinationKey(), uploadId, partETags);
    CompleteMultipartUploadResult completeMultipartUploadResult = this.completeMultipartUpload(completeMultipartUploadRequest);
    CopyObjectResult result = new CopyObjectResult();
    result.setEtag(completeMultipartUploadResult.getETag());
    return result;
  }
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:48,代码来源:SmartOSSClient.java

示例4: doMultiPartUpload

import com.aliyun.oss.model.InitiateMultipartUploadResult; //导入方法依赖的package包/类
/**
 * Do OSS multiple part upload
 *
 * @param putObjectRequest
 * @return
 */
private PutObjectResult doMultiPartUpload(PutObjectRequest putObjectRequest) {

  File backupFile = putObjectRequest.getFile();

  //Claim a upload id firstly
  String uploadId;
  InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(putObjectRequest.getBucketName(), putObjectRequest.getKey());
  InitiateMultipartUploadResult result = this.initiateMultipartUpload(request);
  uploadId = result.getUploadId();

  long optimalPartSize = calculateOptimalPartSize(backupFile);
  int totalParts = (int) Math.ceil((double) backupFile.length() / optimalPartSize);

  //Upload multi-parts to the bucket
  if (LOG.isInfoEnabled()) {
    LOG.info("Begin to upload multi-parts to OSS from a {}\n", backupFile.getPath());
  }

  List<Future<PartETag>> futures = new ArrayList<Future<PartETag>>();
  for (int i = 0; i < totalParts; i++) {
    long startPos = i * optimalPartSize;
    long curPartSize = (i + 1 == totalParts) ? (backupFile.length() - startPos) : optimalPartSize;

    futures.add(threadPoolExecutor.submit(new PartUploadCallable(putObjectRequest.getBucketName(), putObjectRequest.getKey(),
            backupFile, startPos, curPartSize, i + 1, uploadId)));
  }

  List<PartETag> partETags = collectPartETags(futures);

  //Verify whether all parts are finished
  if (partETags.size() != totalParts) {
    throw new IllegalStateException("Upload multi-parts fail due to some parts are not finished yet");
  } else {
    LOG.info("Succeed to complete multi-parts into an object named {}", putObjectRequest.getKey());
  }

  // Make part numbers in ascending order
  Collections.sort(partETags, new Comparator<PartETag>() {
    @Override
    public int compare(PartETag p1, PartETag p2) {
      return p1.getPartNumber() - p2.getPartNumber();
    }
  });

  LOG.info("Completing to upload multi-parts\n");
  CompleteMultipartUploadRequest completeMultipartUploadRequest =
          new CompleteMultipartUploadRequest(putObjectRequest.getBucketName(), putObjectRequest.getKey(), uploadId, partETags);
  CompleteMultipartUploadResult completeResult = this.completeMultipartUpload(completeMultipartUploadRequest);
  PutObjectResult putObjectResult = new PutObjectResult();
  putObjectResult.setETag(completeResult.getETag());
  return putObjectResult;

}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:60,代码来源:SmartOSSClient.java


注:本文中的com.aliyun.oss.model.InitiateMultipartUploadResult.getUploadId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。