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


Java PutObjectResult类代码示例

本文整理汇总了Java中com.qcloud.cos.model.PutObjectResult的典型用法代码示例。如果您正苦于以下问题:Java PutObjectResult类的具体用法?Java PutObjectResult怎么用?Java PutObjectResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: UseTemporyTokenUploadAndDownload

import com.qcloud.cos.model.PutObjectResult; //导入依赖的package包/类
public static void UseTemporyTokenUploadAndDownload() {
	// 使用云api秘钥,可以获取一个临时secret id,secret key和session token,
	BasicSessionCredentials cred = getSessionCredential();
	// 设置区域, 这里设置为北京一区
       ClientConfig clientConfig = new ClientConfig(new Region("ap-beijing-1"));
       // 生成cos客户端对象
       COSClient cosClient = new COSClient(cred, clientConfig);
       // 上传的bucket名字
       String bucketName = "rabbitliutj-1000000";
       // 上传object, 建议20M以下的文件使用该接口
       File localFile = new File("src/test/resources/len5M.txt");
       String key = "/upload_single_demo5M.txt";

       // 上传
       PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
       ObjectMetadata objectMetadata = new ObjectMetadata();
       PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
       System.out.println(putObjectResult.getMetadata());

       // 下载
       File downFile = new File("src/test/resources/len5M_down.txt");
       GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
       ObjectMetadata downObjectMeta = cosClient.getObject(getObjectRequest, downFile);
       // 关闭客户端(关闭后台线程)
       cosClient.shutdown();
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v5,代码行数:27,代码来源:TemporyTokenDemo.java

示例2: putObjectFromLocalFile

import com.qcloud.cos.model.PutObjectResult; //导入依赖的package包/类
protected static void putObjectFromLocalFile(File localFile, String key) {
    if (!judgeUserInfoValid()) {
        return;
    }

    AccessControlList acl = new AccessControlList();
    UinGrantee uinGrantee = new UinGrantee("734000014");
    acl.grantPermission(uinGrantee, Permission.Read);
    PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, localFile);
    putObjectRequest.setStorageClass(StorageClass.Standard_IA);
    // putObjectRequest.setCannedAcl(CannedAccessControlList.PublicRead);
    // putObjectRequest.setAccessControlList(acl);

    PutObjectResult putObjectResult = cosclient.putObject(putObjectRequest);
    String etag = putObjectResult.getETag();
    String expectEtag = null;
    try {
        expectEtag = Md5Utils.md5Hex(localFile);
    } catch (IOException e) {
        fail(e.toString());
    }
    assertEquals(expectEtag, etag);

}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v5,代码行数:25,代码来源:AbstractCOSClientTest.java

示例3: createPutObjectResult

import com.qcloud.cos.model.PutObjectResult; //导入依赖的package包/类
private static PutObjectResult createPutObjectResult(ObjectMetadata metadata) {
    final PutObjectResult result = new PutObjectResult();
    result.setVersionId(metadata.getVersionId());
    result.setETag(metadata.getETag());
    result.setExpirationTime(metadata.getExpirationTime());
    result.setMetadata(metadata);
    return result;
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v5,代码行数:9,代码来源:COSClient.java

示例4: uploadInOneChunk

import com.qcloud.cos.model.PutObjectResult; //导入依赖的package包/类
/**
 * Uploads the given request in a single chunk and returns the result.
 */
private UploadResult uploadInOneChunk() {
    PutObjectResult putObjectResult = cos.putObject(origReq);

    UploadResult uploadResult = new UploadResult();
    uploadResult.setBucketName(origReq.getBucketName());
    uploadResult.setKey(origReq.getKey());
    uploadResult.setETag(putObjectResult.getETag());
    uploadResult.setVersionId(putObjectResult.getVersionId());
    return uploadResult;
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v5,代码行数:14,代码来源:UploadCallable.java

示例5: main

import com.qcloud.cos.model.PutObjectResult; //导入依赖的package包/类
public static void main(String[] args) {
	COSCredentials cred = new BasicCOSCredentials("1251505282", "AKIDCXrebct3IXl0HXrvcHHLYp6UpKwMlFY0", "kaQEEFIMRYhr2OqImHoR5jQbgow7KYn2");
	ClientConfig clientConfig = new ClientConfig(new Region("ap-shanghai"));
	COSClient cosClient = new COSClient(cred, clientConfig);
	String bucketName = "minsx";
	
	File localFile = new File("E:\\document\\编程文档\\Java真题库_电子书.pdf");
	String key = "/腾讯-COS.pdf";
	PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
	PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
	cosClient.shutdown();
	
	new CosClientException("");
	new CosServiceException("");
	
	
	//String result = cosClient.statFile(new StatFileRequest(bucketName, "/腾讯-COS.pdf"));
	String result = "{\"code\":0,\"message\":\"SUCCESS\",\"request_id\":\"NWEwMTlkMTNfZTlhMDY4NjRfOTRkZl8yMTkwYjA=\",\"data\":{\"access_url\":\"http://minsx-1251505282.file.myqcloud.com/%E8%85%BE%E8%AE%AF-COS.pdf\",\"authority\":\"eInvalid\",\"biz_attr\":\"\",\"ctime\":1509793525,\"custom_headers\":{},\"filelen\":3032065,\"filesize\":3032065,\"forbid\":0,\"mtime\":1509793525,\"sha\":\"8d32e1cc59a978a84556ab38fa9ca7ebbcdd7b04\",\"slicesize\":1048576,\"source_url\":\"http://minsx-1251505282.cossh.myqcloud.com/%E8%85%BE%E8%AE%AF-COS.pdf\"}}\r\n";
	System.out.println(result);
	JSONObject jsonObject = JSON.parseObject(result);
	System.out.println("code = "+jsonObject.get("code"));
	System.out.println("message = "+jsonObject.get("message"));
	System.out.println("access_url = "+jsonObject.getJSONObject("data").get("access_url"));
	System.out.println("authority = "+jsonObject.getJSONObject("data").get("authority"));
	System.out.println("biz_attr = "+jsonObject.getJSONObject("data").get("biz_attr"));
	System.out.println("ctime = "+jsonObject.getJSONObject("data").get("ctime"));
	System.out.println("custom_headers = "+jsonObject.getJSONObject("data").get("custom_headers"));
	System.out.println("filelen = "+jsonObject.getJSONObject("data").get("filelen"));
	System.out.println("filesize = "+jsonObject.getJSONObject("data").get("filesize"));
	System.out.println("forbid = "+jsonObject.getJSONObject("data").get("forbid"));
	System.out.println("mtime = "+jsonObject.getJSONObject("data").get("mtime"));
	System.out.println("sha = "+jsonObject.getJSONObject("data").get("sha"));
	System.out.println("slicesize = "+jsonObject.getJSONObject("data").get("slicesize"));
	System.out.println("source_url = "+jsonObject.getJSONObject("data").get("source_url"));
	
	System.out.println(new Date(1509793525000L));
	
}
 
开发者ID:MinsxCloud,项目名称:minsx-ccs,代码行数:39,代码来源:App.java

示例6: putObject

import com.qcloud.cos.model.PutObjectResult; //导入依赖的package包/类
@Override
public PutObjectResult putObject(String bucketName, String key, File file)
        throws CosClientException, CosServiceException {
    return putObject(
            new PutObjectRequest(bucketName, key, file).withMetadata(new ObjectMetadata()));
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v5,代码行数:7,代码来源:COSClient.java

示例7: putObject

import com.qcloud.cos.model.PutObjectResult; //导入依赖的package包/类
public PutObjectResult putObject(PutObjectRequest request){
	return cosClient.putObject(request);
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:4,代码来源:CosClientWrapper.java

示例8: storeResult

import com.qcloud.cos.model.PutObjectResult; //导入依赖的package包/类
public Optional<PutObjectResult> storeResult() {
	return Optional.ofNullable(storeResult);
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:4,代码来源:CosClientWrapper.java

示例9: putObject

import com.qcloud.cos.model.PutObjectResult; //导入依赖的package包/类
/**
 * <p>
 * Uploads a new object to the specified bucket. The <code>PutObjectRequest</code> contains all
 * the details of the request, including the bucket to upload to, the key the object will be
 * uploaded under, and the file or input stream containing the data to upload.
 * </p>
 * <p>
 * never stores partial objects; if during this call an exception wasn't thrown, the entire
 * object was stored.
 * </p>
 * <p>
 * Depending on whether a file or input stream is being uploaded, this method has slightly
 * different behavior.
 * </p>
 * <p>
 * When uploading a file:
 * </p>
 * <ul>
 * <li>The client automatically computes a checksum of the file. uses checksums to validate the
 * data in each file.</li>
 * <li>Using the file extension, attempts to determine the correct content type and content
 * disposition to use for the object.</li>
 * </ul>
 * <p>
 * When uploading directly from an input stream:
 * </p>
 * <ul>
 * <li>Be careful to set the correct content type in the metadata object before directly sending
 * a stream. Unlike file uploads, content types from input streams cannot be automatically
 * determined. If the caller doesn't explicitly set the content type, it will not be set in .
 * </li>
 * <li>Content length <b>must</b> be specified before data can be uploaded to . Qcloud COS
 * explicitly requires that the content length be sent in the request headers before it will
 * accept any of the data. If the caller doesn't provide the length, the library must buffer the
 * contents of the input stream in order to calculate it.
 * </ul>
 *
 * <p>
 * The specified bucket must already exist and the caller must have {@link Permission#Write}
 * permission to the bucket to upload an object.
 * </p>
 *
 * @param putObjectRequest The request object containing all the parameters to upload a new
 *        object to .
 *
 * @return A {@link PutObjectResult} object containing the information returned by for the newly
 *         created object.
 *
 * @throws CosClientException If any errors are encountered in the client while making the
 *         request or handling the response.
 * @throws CosServiceException If any errors occurred in while processing the request.
 *
 * @see COS#putObject(String, String, File)
 * @see COS#putObject(String, String, InputStream, ObjectMetadata)
 */
public PutObjectResult putObject(PutObjectRequest putObjectRequest)
        throws CosClientException, CosServiceException;
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v5,代码行数:58,代码来源:COS.java


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