public class PutObjectRequest extends AbstractPutObjectRequest implements Serializable
Uploads a new object to the specified Qcloud COS bucket. The PutObjectRequest optionally uploads object metadata and applies a canned access control policy to the new object.
Qcloud COS never stores partial objects; if during this call an exception wasn't thrown, the entire object was stored.
Depending on whether a file or input stream is being uploaded, this request has slightly different behavior.
When uploading a file:
When uploading directly from an input stream, content length must be specified before data can be uploaded to Qcloud COS. If not provided, the library will have to buffer the contents of the input stream in order to calculate it. Qcloud COS explicitly requires that the content length be sent in the request headers before any of the data is sent.
Qcloud COS is a distributed system. If Qcloud COS receives multiple write requests for the same object nearly simultaneously, all of the objects might be stored. However, only one object will obtain the key.
Note: Qcloud COS does not provide object locking; if this is needed, make sure to build it into the application layer.
If the caller specifies a location constraint when creating a bucket, all objects added to the bucket are stored in the same region as the bucket. For example, if specifying a Europe (EU) region constraint for a bucket, all of that bucket's objects are stored in the EU region.
The specified bucket must already exist and the caller must have
Permission.Write
permission to the bucket to upload an object.
CosDataSource.Utils
Constructor and Description |
---|
PutObjectRequest(String bucketName,
String key,
File file)
Constructs a new
PutObjectRequest object to upload a file to the
specified bucket and key. |
PutObjectRequest(String bucketName,
String key,
InputStream input,
ObjectMetadata metadata)
Constructs a new
PutObjectRequest object to upload a stream of data to
the specified bucket and key. |
Modifier and Type | Method and Description |
---|---|
PutObjectRequest |
clone()
Returns a clone (as deep as possible) of this request object.
|
boolean |
isEnableResumableUpload() |
void |
setEnableResumableUpload(boolean useResumableUpload) |
PutObjectRequest |
withAccessControlList(AccessControlList accessControlList)
Sets the optional access control list for the new object.
|
PutObjectRequest |
withBucketName(String bucketName)
Sets the name of the bucket where this request will upload a new object to.
|
PutObjectRequest |
withCannedAcl(CannedAccessControlList cannedAcl)
Sets the optional pre-configured access control policy to use for the new object.
|
PutObjectRequest |
withFile(File file)
Sets the file containing the data to be uploaded to Qcloud COS.
|
PutObjectRequest |
withInputStream(InputStream inputStream)
Sets the input stream containing the data to be uploaded to Qcloud COS.
|
PutObjectRequest |
withKey(String key)
Sets the key under which to store the new object.
|
PutObjectRequest |
withMetadata(ObjectMetadata metadata)
Sets the optional metadata instructing Qcloud COS how to handle the uploaded data (e.g.
|
PutObjectRequest |
withRedirectLocation(String redirectLocation)
Sets the optional redirect location for the new object.Returns this
AbstractPutObjectRequest , enabling additional method calls to be chained together. |
PutObjectRequest |
withSSECOSKeyManagementParams(SSECOSKeyManagementParams sseCOSKeyManagementParams)
Sets the COS Key Management System parameters used to encrypt the object on server side.
|
PutObjectRequest |
withSSECustomerKey(SSECustomerKey sseKey)
Sets the optional customer-provided server-side encryption key to use to encrypt the uploaded
object, and returns the updated request object so that additional method calls can be chained
together.
|
PutObjectRequest |
withStorageClass(StorageClass storageClass)
Sets the optional Qcloud COS storage class to use when storing the new object.
|
PutObjectRequest |
withStorageClass(String storageClass)
Sets the optional Qcloud COS storage class to use when storing the new object.
|
copyPutObjectBaseTo, getAccessControlList, getBucketName, getCannedAcl, getFile, getInputStream, getKey, getMetadata, getPicOperations, getRedirectLocation, getSSECOSKeyManagementParams, getSSECustomerKey, getStorageClass, getTrafficLimit, setAccessControlList, setBucketName, setCannedAcl, setFile, setInputStream, setKey, setMetadata, setPicOperations, setRedirectLocation, setSSECOSKeyManagementParams, setSSECustomerKey, setStorageClass, setStorageClass, setTrafficLimit
copyBaseTo, getCiSpecialEndParameter, getCloneRoot, getCloneSource, getCosCredentials, getCustomQueryParameters, getCustomRequestHeaders, getFixedEndpointAddr, getGeneralProgressListener, getReadLimit, getRequestClientOptions, putCustomQueryParameter, putCustomRequestHeader, setCiSpecialEndParameter, setCosCredentials, setFixedEndpointAddr, setGeneralProgressListener, withGeneralProgressListener
public PutObjectRequest(String bucketName, String key, File file)
PutObjectRequest
object to upload a file to the
specified bucket and key. After constructing the request,
users may optionally specify object metadata or a canned ACL as well.bucketName
- The name of an existing bucket to which the new object will be
uploaded.key
- The key under which to store the new object.file
- The path of the file to upload to Qcloud COS.public PutObjectRequest(String bucketName, String key, InputStream input, ObjectMetadata metadata)
PutObjectRequest
object to upload a stream of data to
the specified bucket and key. After constructing the request,
users may optionally specify object metadata or a canned ACL as well.
Content length for the data stream must be specified in the object metadata parameter; Qcloud COS requires it be passed in before the data is uploaded. Failure to specify a content length will cause the entire contents of the input stream to be buffered locally in memory so that the content length can be calculated, which can result in negative performance problems.
bucketName
- The name of an existing bucket to which the new object will be
uploaded.key
- The key under which to store the new object.input
- The stream of data to upload to Qcloud COS.metadata
- The object metadata. At minimum this specifies the
content length for the stream of data being uploaded.public PutObjectRequest clone()
clone
in class AbstractPutObjectRequest
Object.clone()
public PutObjectRequest withBucketName(String bucketName)
AbstractPutObjectRequest
In order to upload the object, users must have Permission.Write
permission granted.
withBucketName
in class AbstractPutObjectRequest
bucketName
- The name of an existing bucket where this request will upload a new object
to. In order to upload the object, users must have Permission.Write
permission
granted.AbstractPutObjectRequest
, enabling additional method calls to be chained
together.AbstractPutObjectRequest.getBucketName()
,
AbstractPutObjectRequest.setBucketName(String)
public PutObjectRequest withKey(String key)
AbstractPutObjectRequest
withKey
in class AbstractPutObjectRequest
key
- The key under which to store the new object.AbstractPutObjectRequest
, enabling additional method calls to be chained
together.AbstractPutObjectRequest.getKey()
,
AbstractPutObjectRequest.setKey(String)
public PutObjectRequest withStorageClass(String storageClass)
AbstractPutObjectRequest
AbstractPutObjectRequest
, enabling additional method calls to be chained together. If
not specified, the default standard storage class will be used when storing the object.
For more information on Qcloud COS storage classes and available values, see the
StorageClass
enumeration.
withStorageClass
in class AbstractPutObjectRequest
storageClass
- The storage class to use when storing the new object.AbstractPutObjectRequest
, enabling additional method calls to be chained
together.AbstractPutObjectRequest.getStorageClass()
,
AbstractPutObjectRequest.setStorageClass(StorageClass)
,
AbstractPutObjectRequest.setStorageClass(String)
,
AbstractPutObjectRequest.withStorageClass(StorageClass)
public PutObjectRequest withStorageClass(StorageClass storageClass)
AbstractPutObjectRequest
AbstractPutObjectRequest
, enabling additional method calls to be chained together. If
not specified, the default standard storage class will be used when storing the object.
For more information on Qcloud COS storage classes and available values, see the
StorageClass
enumeration.
withStorageClass
in class AbstractPutObjectRequest
storageClass
- The storage class to use when storing the new object.AbstractPutObjectRequest
, enabling additional method calls to be chained
together.AbstractPutObjectRequest.getStorageClass()
,
AbstractPutObjectRequest.setStorageClass(StorageClass)
,
AbstractPutObjectRequest.setStorageClass(String)
,
AbstractPutObjectRequest.withStorageClass(String)
public PutObjectRequest withFile(File file)
AbstractPutObjectRequest
AbstractPutObjectRequest
, enabling additional method calls to be chained together.
Either specify a file or an input stream containing the data to be uploaded to Qcloud COS; both cannot be specified.
withFile
in class AbstractPutObjectRequest
file
- The file containing the data to be uploaded to Qcloud COS.AbstractPutObjectRequest
, enabling additional method calls to be chained
together.AbstractPutObjectRequest.getFile()
,
AbstractPutObjectRequest.setFile(File)
,
AbstractPutObjectRequest.getInputStream()
,
AbstractPutObjectRequest.setInputStream(InputStream)
public PutObjectRequest withMetadata(ObjectMetadata metadata)
AbstractPutObjectRequest
AbstractPutObjectRequest
, enabling additional method calls to be chained together.
If uploading from an input stream, always specify metadata with the content size set. Otherwise the contents of the input stream have to be buffered in memory before being sent to Qcloud COS. This can cause very negative performance impacts.
withMetadata
in class AbstractPutObjectRequest
metadata
- The optional metadata instructing Qcloud COS how to handle the uploaded data
(e.g. custom user metadata, hooks for specifying content type, etc.).AbstractPutObjectRequest
, enabling additional method calls to be chained
together.AbstractPutObjectRequest.getMetadata()
,
AbstractPutObjectRequest.setMetadata(ObjectMetadata)
public PutObjectRequest withCannedAcl(CannedAccessControlList cannedAcl)
AbstractPutObjectRequest
AbstractPutObjectRequest
, enabling additional method calls to be chained
together.withCannedAcl
in class AbstractPutObjectRequest
cannedAcl
- The optional pre-configured access control policy to use for the new object.AbstractPutObjectRequest
, enabling additional method calls to be chained
together.AbstractPutObjectRequest.getCannedAcl()
,
AbstractPutObjectRequest.setCannedAcl(CannedAccessControlList)
public PutObjectRequest withAccessControlList(AccessControlList accessControlList)
AbstractPutObjectRequest
AbstractPutObjectRequest
, enabling additional method calls to
be chained together.withAccessControlList
in class AbstractPutObjectRequest
accessControlList
- The access control list for the new object.public PutObjectRequest withInputStream(InputStream inputStream)
AbstractPutObjectRequest
AbstractPutObjectRequest
, enabling additional method calls to be chained together.
Either specify a file or an input stream containing the data to be uploaded to Qcloud COS; both cannot be specified.
withInputStream
in class AbstractPutObjectRequest
inputStream
- The InputStream containing the data to be uploaded to Qcloud COS.AbstractPutObjectRequest.getInputStream()
,
AbstractPutObjectRequest.setInputStream(InputStream)
,
AbstractPutObjectRequest.getFile()
,
AbstractPutObjectRequest.setFile(File)
public PutObjectRequest withRedirectLocation(String redirectLocation)
AbstractPutObjectRequest
AbstractPutObjectRequest
, enabling additional method calls to be chained together.withRedirectLocation
in class AbstractPutObjectRequest
redirectLocation
- The redirect location for the new object.public PutObjectRequest withSSECustomerKey(SSECustomerKey sseKey)
AbstractPutObjectRequest
withSSECustomerKey
in class AbstractPutObjectRequest
sseKey
- The optional customer-provided server-side encryption key to use to encrypt the
uploaded object.public PutObjectRequest withSSECOSKeyManagementParams(SSECOSKeyManagementParams sseCOSKeyManagementParams)
AbstractPutObjectRequest
withSSECOSKeyManagementParams
in class AbstractPutObjectRequest
public void setEnableResumableUpload(boolean useResumableUpload)
public boolean isEnableResumableUpload()
Copyright © 2024. All rights reserved.