本文整理匯總了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();
}
示例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);
}
示例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;
}
示例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;
}
示例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));
}
示例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()));
}
示例7: putObject
import com.qcloud.cos.model.PutObjectResult; //導入依賴的package包/類
public PutObjectResult putObject(PutObjectRequest request){
return cosClient.putObject(request);
}
示例8: storeResult
import com.qcloud.cos.model.PutObjectResult; //導入依賴的package包/類
public Optional<PutObjectResult> storeResult() {
return Optional.ofNullable(storeResult);
}
示例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;