com.netease.cloud.services.nos
public class NosClient extends WebServiceClient implements Nos
The client for accessing the Netease NOS web service.
The client provides storage service on the Internet.
This client can be used to store and retrieve any amount of data, at any time, from anywhere on the web.
client, clientConfiguration, endpoint, requestHandlers
Constructor and Description |
---|
NosClient()
Constructs a new NOS client that will make anonymous requests to NOS.
|
NosClient(Credentials Credentials)
Constructs a new NOS client using the specified credentials to access NOS.
|
NosClient(Credentials Credentials,
ClientConfiguration clientConfiguration)
Constructs a new NOS client using the specified credentials and client configuration to access NOS.
|
NosClient(CredentialsProvider credentialsProvider)
Constructs a new NOS client using the specified credentials provider to access NOS.
|
NosClient(CredentialsProvider credentialsProvider,
ClientConfiguration clientConfiguration)
Constructs a new NOS client using the specified credentials and client configuration to access NOS.
|
Modifier and Type | Method and Description |
---|---|
void |
abortMultipartUpload(AbortMultipartUploadRequest abortMultipartUploadRequest)
Aborts a multipart upload.
|
void |
addRequestHandler(RequestHandler requestHandler)
Appends a request handler to the list of registered handlers that are run as part of a request's lifecycle.
|
CompleteMultipartUploadResult |
completeMultipartUpload(CompleteMultipartUploadRequest completeMultipartUploadRequest)
Completes a multipart upload by assembling previously uploaded parts.
|
void |
copyObject(CopyObjectRequest copyObjectRequest)
Copies a source object to a new destination in NOS.
|
void |
copyObject(String sourceBucketName,
String sourceKey,
String destinationBucketName,
String destinationKey)
Copies a source object to a new destination in NOS.
|
Bucket |
createBucket(CreateBucketRequest createBucketRequest)
Creates a new NOS bucket ,and you can specified the region,ACL,and
whether this bucket is deduplicate supported or not.
|
Bucket |
createBucket(String bucketName)
Creates a new NOS bucket in the default region,
Region.CN_Hnagzhou .and default ACL
CannedAccessControlList.Private ,and default deduplicate status
DeduplicateStatus#Disabled |
Bucket |
createBucket(String bucketName,
Region region)
Creates a new NOS bucket with the specified name in the specified
region,and is supported dedupicate or not.
|
Bucket |
createBucket(String bucketName,
String region)
Creates a new NOS bucket with the specified name in the specified
region,and is supported dedupicate or not.
|
protected <X extends WebServiceRequest> |
createRequest(String bucketName,
String key,
X originalRequest,
HttpMethodName httpMethod)
Creates and initializes a new request object for the specified NOS resource.
|
protected Signer |
createSigner(Request<?> request,
String bucketName,
String key) |
void |
deleteBucket(DeleteBucketRequest deleteBucketRequest)
Deletes the specified bucket.
|
void |
deleteBucket(String bucketName)
Deletes the specified bucket.
|
void |
deleteBucketLifecycleConfiguration(String bucketName)
Removes the lifecycle configuration for the bucket specified.
|
void |
deleteObject(DeleteObjectRequest deleteObjectRequest)
Deletes the specified object in the specified bucket.
|
void |
deleteObject(String bucketName,
String key)
Deletes the specified object in the specified bucket.
|
DeleteObjectsResult |
deleteObjects(DeleteObjectsRequest deleteObjectsRequest)
Deletes multiple objects in a single bucket from NOS.
|
boolean |
doesBucketExist(HeadBucketRequest headBucketRequest) |
boolean |
doesBucketExist(String bucketName)
check bucket existence
|
boolean |
doesObjectExist(String bucketName,
String key)
See if the specified object exists.
|
URL |
generatePresignedUrl(GeneratePresignedUrlRequest generatePresignedUrlRequest)
Returns a pre-signed URL for accessing an NOS resource.
|
URL |
generatePresignedUrl(String bucketName,
String key,
Date expiration)
Returns a pre-signed URL for accessing an NOS resource.
|
URL |
generatePresignedUrl(String bucketName,
String key,
Date expiration,
HttpMethod method)
Returns a pre-signed URL for accessing an NOS resource.
|
CannedAccessControlList |
getBucketAcl(GetBucketAclRequest getBucketAclRequest)
Gets the (ACL) of the specified bucket,Each bucket has an ACL that
defines its access control policy.
|
CannedAccessControlList |
getBucketAcl(String bucketName)
Gets the
CannedAccessControlList (ACL) of the specified
bucket,Each bucket has an ACL that defines its access control policy. |
GetBucketDefault404Result |
getBucketDefault404(GetBucketDefault404Request getBucketDefault404Request) |
GetBucketDefault404Result |
getBucketDefault404(String bucketName) |
BucketLifecycleConfiguration |
getBucketLifecycleConfiguration(String bucketName)
Gets the lifecycle configuration for the specified bucket.
|
String |
getBucketLocation(GetBucketLocationRequest getBucketLocationRequest)
Gets the geographical region where Nos stores the specified bucket.
|
String |
getBucketLocation(String bucketName)
Gets the geographical region where Nos stores the specified bucket.
|
GetBucketStatsResult |
getBucketStats(String bucketName)
Gets the stats(objectCount, storageCapacity, deduplicationRate) for the bucket specified.
|
NOSObject |
getObject(GetObjectRequest getObjectRequest)
Gets the object stored in NOS under the specified bucket and key.
|
ObjectMetadata |
getObject(GetObjectRequest getObjectRequest,
File destinationFile)
Gets the object metadata for the object stored in NOS under the specified
bucket and key, and saves the object contents to the specified file.
|
NOSObject |
getObject(String bucketName,
String key)
Gets the object stored in NOS under the specified bucket and key.
|
ObjectMetadata |
getObjectMetadata(GetObjectMetadataRequest getObjectMetadataRequest)
Gets the metadata for the specified object without actually fetching the
object itself.
|
ObjectMetadata |
getObjectMetadata(String bucketName,
String key)
Gets the metadata for the specified object without actually fetching the
object itself.
|
InitiateMultipartUploadResult |
initiateMultipartUpload(InitiateMultipartUploadRequest initiateMultipartUploadRequest)
Initiates a multipart upload and returns an InitiateMultipartUploadResult
which contains an upload ID.
|
List<Bucket> |
listBuckets()
List your all buckets owned by you.
|
List<Bucket> |
listBuckets(ListBucketsRequest listBucketsRequest) |
MultipartUploadListing |
listMultipartUploads(ListMultipartUploadsRequest listMultipartUploadsRequest)
Lists in-progress multipart uploads.
|
ObjectListing |
listObjects(ListObjectsRequest listObjectsRequest)
According to some query condition to return a list of summary information
about the objects in the specified buckets.
|
ObjectListing |
listObjects(String bucketName)
Returns a list of summary information about the objects in the specified
buckets.
|
PartListing |
listParts(ListPartsRequest listPartsRequest)
Lists the parts that have been uploaded for a specific multipart upload.
|
static void |
main(String[] args) |
void |
mediaSaveAsObject(MediaSaveAsRequest mediaSaveAsRequest) |
void |
mediaSaveAsObject(String sourceBucketName,
String sourceKey,
String destinationBucketName,
String destinationKey,
String mediaOperation) |
void |
moveObject(MoveObjectRequest moveObjectRequest)
move a source object to a new destination in NOS.
|
void |
moveObject(String sourceBucketName,
String sourceKey,
String destinationBucketName,
String destinationKey)
move a source object to a new destination in NOS.
|
protected static void |
populateRequestMetadata(Request<?> request,
ObjectMetadata metadata)
Populates the specified request object with the appropriate headers from the
ObjectMetadata object. |
protected <T> void |
presignRequest(Request<T> request,
HttpMethod methodName,
String bucketName,
String key,
Date expiration,
String subResource)
Pre-signs the specified request, using a signature query-string parameter.
|
PutObjectResult |
putObject(PutObjectRequest putObjectRequest)
Uploads a new object to the specified NOS bucket.
|
PutObjectResult |
putObject(String bucketName,
File file) |
PutObjectResult |
putObject(String bucketName,
String key,
File file)
Uploads the specified file to NOS under the specified bucket and key
name.
|
PutObjectResult |
putObject(String bucketName,
String key,
InputStream input,
ObjectMetadata metadata)
Uploads the specified input stream and object metadata to NOS under the
specified bucket and key name.
|
void |
putObjectMeta(String bucketName,
String key,
ObjectMetadata metadata) |
void |
setBucketAcl(SetBucketAclRequest setBucketAclRequest)
Sets the
CannedAccessControlList (ACL)for the specified
bucket,Each bucket has an ACL that defines its access control policy.if
the ACL is private,anybody expect you can access objects in the bucket,if
the ACL is private-read,then others can download the objects in this
bucket. |
void |
setBucketAcl(String bucketName,
CannedAccessControlList acl)
Sets the
CannedAccessControlList (ACL)for the specified
bucket,Each bucket has an ACL that defines its access control policy.if
the ACL is private,anybody expect you can access objects in the bucket,if
the ACL is private-read,then others can download the objects in this
bucket. |
void |
setBucketDefault404(PutBucketDefault404Request putBucketDefault404Request) |
void |
setBucketDefault404(String bucketName,
String default404Object) |
void |
setBucketLifecycleConfiguration(SetBucketLifecycleConfigurationRequest setBucketLifecycleConfigurationRequest)
Sets the lifecycle configuration for the specified bucket.
|
void |
setBucketLifecycleConfiguration(String bucketName,
BucketLifecycleConfiguration bucketLifecycleConfiguration)
Sets the lifecycle configuration for the specified bucket.
|
String |
signString(String stringToSign) |
UploadPartResult |
uploadPart(UploadPartRequest uploadPartRequest)
Uploads a part in a multipart upload.
|
boolean |
validateStringSignature(String stringToSign,
String signature) |
createExecutionContext, removeRequestHandler, setConfiguration, setEndpoint, shutdown
public NosClient()
Constructs a new NOS client that will make anonymous requests to NOS.
Only a subset of the NOS API will work with anonymous (i.e. unsigned) requests, but this can prove useful in some situations. For example:
public NosClient(Credentials Credentials)
Credentials
- The credentials to use when making requests to NOS with this client.public NosClient(Credentials Credentials, ClientConfiguration clientConfiguration)
Credentials
- The credentials to use when making requests to NOS with this client.clientConfiguration
- The client configuration options controlling how this client connects to NOS (e.g. proxy settings,
retry counts, etc).public NosClient(CredentialsProvider credentialsProvider)
credentialsProvider
- The credentials provider which will provide credentials to authenticate requests with services.public NosClient(CredentialsProvider credentialsProvider, ClientConfiguration clientConfiguration)
credentialsProvider
- The credentials provider which will provide credentials to authenticate requests with services.clientConfiguration
- The client configuration options controlling how this client connects to NOS (e.g. proxy settings,
retry counts, etc).public void addRequestHandler(RequestHandler requestHandler)
addRequestHandler
in class WebServiceClient
requestHandler
- The new handler to add to the current list of request handlers.public ObjectListing listObjects(String bucketName) throws ClientException, ServiceException
Nos
Returns a list of summary information about the objects in the specified buckets. List results are always returned in alphabetical order.
listObjects
in interface Nos
bucketName
- The name of the bucket to be listed.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server point.public ObjectListing listObjects(ListObjectsRequest listObjectsRequest) throws ClientException, ServiceException
Nos
According to some query condition to return a list of summary information about the objects in the specified buckets.
listObjects
in interface Nos
listObjectsRequest
- The request object containing all query conditions for listing
the objects in a specified bucket.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server point.Nos.listObjects(String)
public GetBucketStatsResult getBucketStats(String bucketName) throws ClientException, ServiceException
Nos
getBucketStats
in interface Nos
bucketName
- The name of the bucket for which to get the statsClientException
ServiceException
public List<Bucket> listBuckets(ListBucketsRequest listBucketsRequest) throws ClientException, ServiceException
listBuckets
in interface Nos
ClientException
ServiceException
Nos.listBuckets()
public List<Bucket> listBuckets() throws ClientException, ServiceException
Nos
List your all buckets owned by you.
listBuckets
in interface Nos
ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server point.public Bucket createBucket(String bucketName) throws ClientException, ServiceException
Nos
Creates a new NOS bucket in the default region,
Region.CN_Hnagzhou
.and default ACL
CannedAccessControlList.Private
,and default deduplicate status
DeduplicateStatus#Disabled
createBucket
in interface Nos
bucketName
- The name of the bucket to create. All buckets in NOS share a
single namespace; ensure the bucket is given a unique name. In
addition,the bucket name must follow orders:
ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server point.Nos.createBucket(CreateBucketRequest)
public Bucket createBucket(String bucketName, Region region) throws ClientException, ServiceException
Nos
Creates a new NOS bucket with the specified name in the specified region,and is supported dedupicate or not.
createBucket
in interface Nos
bucketName
- The name of the bucket to create. All buckets in NOS share a
single namespace; ensure the bucket is given a unique name. In
addition,the bucket name must follow orders:
region
- The region in which to create the new bucket.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointpublic Bucket createBucket(String bucketName, String region) throws ClientException, ServiceException
Nos
Creates a new NOS bucket with the specified name in the specified region,and is supported dedupicate or not.
createBucket
in interface Nos
bucketName
- The name of the bucket to create. All buckets in NOS share a
single namespace; ensure the bucket is given a unique name. In
addition,the bucket name must follow orders:
region
- The NOS region in which to create the new bucket. String value
of Region
.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointpublic Bucket createBucket(CreateBucketRequest createBucketRequest) throws ClientException, ServiceException
Nos
Creates a new NOS bucket ,and you can specified the region,ACL,and whether this bucket is deduplicate supported or not.
createBucket
in interface Nos
createBucketRequest
- The request object containing all options for creating an NOS
bucket.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server point.Nos.createBucket(String)
public CannedAccessControlList getBucketAcl(String bucketName) throws ClientException, ServiceException
Nos
Gets the CannedAccessControlList
(ACL) of the specified
bucket,Each bucket has an ACL that defines its access control policy.
getBucketAcl
in interface Nos
bucketName
- The name of the bucket whose ACL is being retrieved.CannedAccessControlList
for the specified NOS
bucket.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointpublic CannedAccessControlList getBucketAcl(GetBucketAclRequest getBucketAclRequest) throws ClientException, ServiceException
Nos
Gets the (ACL) of the specified bucket,Each bucket has an ACL that defines its access control policy.
getBucketAcl
in interface Nos
getBucketAclRequest
- The request containing the name of the bucket whose ACL is
being retrieved.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointpublic void setBucketAcl(SetBucketAclRequest setBucketAclRequest) throws ClientException, ServiceException
Nos
Sets the CannedAccessControlList
(ACL)for the specified
bucket,Each bucket has an ACL that defines its access control policy.if
the ACL is private,anybody expect you can access objects in the bucket,if
the ACL is private-read,then others can download the objects in this
bucket.
setBucketAcl
in interface Nos
setBucketAclRequest
- The request object containing the bucket to modify and the ACL
to set.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointpublic void setBucketAcl(String bucketName, CannedAccessControlList acl) throws ClientException, ServiceException
Nos
Sets the CannedAccessControlList
(ACL)for the specified
bucket,Each bucket has an ACL that defines its access control policy.if
the ACL is private,anybody expect you can access objects in the bucket,if
the ACL is private-read,then others can download the objects in this
bucket.
setBucketAcl
in interface Nos
bucketName
- The name of the bucket whose ACL is being set.acl
- The pre-configured CannedAccessControlLists
to
set for the specified bucket.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointpublic GetBucketDefault404Result getBucketDefault404(String bucketName) throws ClientException, ServiceException
ClientException
ServiceException
public GetBucketDefault404Result getBucketDefault404(GetBucketDefault404Request getBucketDefault404Request) throws ClientException, ServiceException
ClientException
ServiceException
public void setBucketDefault404(String bucketName, String default404Object) throws ClientException, ServiceException
ClientException
ServiceException
public void setBucketDefault404(PutBucketDefault404Request putBucketDefault404Request) throws ClientException, ServiceException
ClientException
ServiceException
public String getBucketLocation(GetBucketLocationRequest getBucketLocationRequest) throws ClientException, ServiceException
Nos
Gets the geographical region where Nos stores the specified bucket.
To view the location constraint of a bucket, the user must be the bucket owner.
Note that Region
enumeration values are not returned
directly from this method.
getBucketLocation
in interface Nos
getBucketLocationRequest
- The request object containing the name of the Nos bucket to
look up. This must be a bucket the user owns.ClientException
- If any errors are encountered in the client point.ServiceException
- If any errors occurred in the server point.public String getBucketLocation(String bucketName) throws ClientException, ServiceException
Nos
Gets the geographical region where Nos stores the specified bucket.
To view the location constraint of a bucket, the user must be the bucket owner.
Note that Region
enumeration values are not returned
directly from this method.
getBucketLocation
in interface Nos
bucketName
- The name of the Nos bucket to look up. This must be a bucket
the user owns.ClientException
- If any errors are encountered in the client point.ServiceException
- If any errors occurred in the server point.public ObjectMetadata getObjectMetadata(String bucketName, String key) throws ClientException, ServiceException
Nos
Gets the metadata for the specified object without actually fetching the object itself. This is useful in obtaining only the object metadata, and avoids wasting bandwidth on fetching the object data.
The object metadata contains information such as content type, content disposition, etc., as well as custom user metadata that can be associated with an object.
getObjectMetadata
in interface Nos
bucketName
- The name of the bucket containing the object's whose metadata
is being retrieved.key
- The key of the object whose metadata is being retrieved.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointNos.getObjectMetadata(GetObjectMetadataRequest)
public ObjectMetadata getObjectMetadata(GetObjectMetadataRequest getObjectMetadataRequest) throws ClientException, ServiceException
Nos
Gets the metadata for the specified object without actually fetching the object itself. This is useful in obtaining only the object metadata, and avoids wasting bandwidth on fetching the object data.
The object metadata contains information such as content type, content disposition, etc., as well as custom user metadata that can be associated with an object.
getObjectMetadata
in interface Nos
getObjectMetadataRequest
- The request object specifying the bucket, key and optional
version ID of the object whose metadata is being retrieved.ClientException
- If any errors are encountered on the client while making the
request orServiceException
- If any errors occurred in NOS server pointNos.getObjectMetadata(String, String)
public NOSObject getObject(String bucketName, String key) throws ClientException, ServiceException
Nos
Gets the object stored in NOS under the specified bucket and key.
Be extremely careful when using this method; the returned NOS object contains a direct stream of data from the HTTP connection. The underlying HTTP connection cannot be closed until the user finishes reading the data and closes the stream. Therefore:
If the object fetched is publicly readable, it can also read it by pasting its URL into a browser.
For more advanced options (such as downloading only a range of an
object's content, or placing constraints on when the object should be
downloaded) callers can use Nos.getObject(GetObjectRequest)
.
getObject
in interface Nos
bucketName
- The name of the bucket containing the desired object.key
- The key under which the desired object is stored.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointNos.getObject(GetObjectRequest)
,
Nos.getObject(GetObjectRequest, File)
public boolean doesObjectExist(String bucketName, String key)
Nos
See if the specified object exists.
doesObjectExist
in interface Nos
bucketName
- The name of the bucket will to be checked.key
- The name of the object will to be checked.true
if the specified object exists in NOS;
otherwise return false
.public boolean doesBucketExist(String bucketName)
doesBucketExist
in interface Nos
bucketName
- public boolean doesBucketExist(HeadBucketRequest headBucketRequest)
headBucketRequest
- public NOSObject getObject(GetObjectRequest getObjectRequest) throws ClientException, ServiceException
Nos
Gets the object stored in NOS under the specified bucket and key. Returns
null
if the specified constraints weren't met.
Callers should be very careful when using this method; the returned NOS object contains a direct stream of data from the HTTP connection. The underlying HTTP connection cannot be closed until the user finishes reading the data and closes the stream. Callers should therefore:
If callers do not follow those rules, then the client can run out of resources if allocating too many open, but unused, HTTP connections.
If the object fetched is publicly readable, it can also read it by pasting its URL into a browser.
When specifying constraints in the request object, the client needs to be
prepared to handle this method returning null
if the
provided constraints aren't met when NOS receives the request.
If the advanced options provided in GetObjectRequest
aren't
needed, use the simpler
Nos.getObject(String bucketName, String key)
method.
getObject
in interface Nos
getObjectRequest
- The request object containing all the options on how to
download the object.null
if constraints were specified but not met.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointNos.getObject(String, String)
,
Nos.getObject(GetObjectRequest, File)
public ObjectMetadata getObject(GetObjectRequest getObjectRequest, File destinationFile) throws ClientException, ServiceException
Nos
Gets the object metadata for the object stored in NOS under the specified
bucket and key, and saves the object contents to the specified file.
Returns null
if the specified constraints weren't met.
Instead of using Nos.getObject(GetObjectRequest)
, use this method
to ensure that the underlying HTTP stream resources are automatically
closed as soon as possible. The NOS clients handles immediate storage of
the object contents to the specified file.
If the object fetched is publicly readable, it can also read it by pasting its URL into a browser.
When specifying constraints in the request object, the client needs to be
prepared to handle this method returning null
if the
provided constraints aren't met when NOS receives the request.
getObject
in interface Nos
getObjectRequest
- The request object containing all the options on how to
download the NOS object content.destinationFile
- Indicates the file (which might already exist) where to save
the object content being downloading from NOS.null
if constraints were specified but not met.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointNos.getObject(String, String)
,
Nos.getObject(GetObjectRequest)
public void deleteBucket(String bucketName) throws ClientException, ServiceException
Nos
Deletes the specified bucket. All objects (and all object versions, if versioning was ever enabled) in the bucket must be deleted before the bucket itself can be deleted.
Only the owner of a bucket can delete it, regardless of the bucket's access control policy.
deleteBucket
in interface Nos
bucketName
- The name of the bucket to delete.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointNos.deleteBucket(String)
public void deleteBucket(DeleteBucketRequest deleteBucketRequest) throws ClientException, ServiceException
Nos
Deletes the specified bucket. All objects (and all object versions, if versioning was ever enabled) in the bucket must be deleted before the bucket itself can be deleted.
Only the owner of a bucket can delete it, regardless of the bucket's access control policy (ACL).
deleteBucket
in interface Nos
deleteBucketRequest
- The request object containing all options for deleting an NOS
bucket.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointNos.deleteBucket(String)
public PutObjectResult putObject(String bucketName, File file) throws ClientException, ServiceException
ClientException
ServiceException
public PutObjectResult putObject(String bucketName, String key, File file) throws ClientException, ServiceException
Nos
Uploads the specified file to NOS under the specified bucket and key name.
NOS never stores partial objects; if during this call an exception wasn't thrown, the entire object was stored.
The client automatically computes a checksum of the file. NOS uses checksums to validate the data in each file.
Using the file extension, NOS attempts to determine the correct content type and content disposition to use for the object.
If versioning is enabled for the specified bucket, this operation will
this operation will never overwrite an existing object with the same key,
but will keep the existing object as an older version until that version
is explicitly deleted (see
Nos#deleteVersion(String, String, String)
.
If versioning is not enabled, this operation will overwrite an existing object with the same key; NOS will store the last write request. NOS does not provide object locking. If NOS receives multiple write requests for the same object nearly simultaneously, all of the objects might be stored. However, a single object will be stored with the final write request.
When specifying a location constraint when creating a bucket, all objects added to the bucket are stored in the bucket's region. For example, if specifying a Europe (EU) region constraint for a bucket, all of that bucket's objects are stored in EU region.
putObject
in interface Nos
bucketName
- The name of an existing bucket, to which you havekey
- The key under which to store the specified file.file
- The file containing the data to be uploaded to NOS.PutObjectResult
object containing the information
returned by NOS for the newly created object.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointNos.putObject(PutObjectRequest)
,
Nos.putObject(String, String, InputStream, ObjectMetadata)
public PutObjectResult putObject(String bucketName, String key, InputStream input, ObjectMetadata metadata) throws ClientException, ServiceException
Nos
Uploads the specified input stream and object metadata to NOS under the specified bucket and key name.
NOS never stores partial objects; if during this call an exception wasn't thrown, the entire object was stored.
The client automatically computes a checksum of the file. This checksum is verified against another checksum that is calculated once the data reaches NOS, ensuring the data has not corrupted in transit over the network.
Using the file extension, NOS attempts to determine the correct content type and content disposition to use for the object.
Content length must be specified before data can be uploaded to NOS. If the caller doesn't provide it, the library will have to buffer the contents of the input stream in order to calculate it because NOS explicitly requires that the content length be sent in the request headers before any of the data is sent.
If versioning is enabled for the specified bucket, this operation will
never overwrite an existing object at the same key, but instead will keep
the existing object around as an older version until that version is
explicitly deleted (see Nos#deleteVersion(String, String, String)
.
If versioning is not enabled, this operation will overwrite an existing object with the same key; NOS will store the last write request. NOS does not provide object locking. If NOS receives multiple write requests for the same object nearly simultaneously, all of the objects might be stored. However, a single object will be stored with the final write request.
When specifying a location constraint when creating a bucket, all objects added to the bucket are stored in the bucket's region. For example, if specifying a Europe (EU) region constraint for a bucket, all of that bucket's objects are stored in EU region.
putObject
in interface Nos
bucketName
- The name of an existing bucket, to which you havekey
- The key under which to store the specified file.input
- The input stream containing the data to be uploaded to NOS.metadata
- Additional metadata instructing NOS how to handle the uploaded
data (e.g. custom user metadata, hooks for specifying content
type, etc.).PutObjectResult
object containing the information
returned by NOS for the newly created object.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointNos.putObject(String, String, File)
,
Nos.putObject(PutObjectRequest)
public PutObjectResult putObject(PutObjectRequest putObjectRequest) throws ClientException, ServiceException
Nos
Uploads a new object to the specified NOS bucket. The
PutObjectRequest
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.
NOS 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 method has slightly different behavior.
When uploading a file:
When uploading directly from an input stream:
If versioning is enabled for the specified bucket, this operation will
never overwrite an existing object with the same key, but will keep the
existing object as an older version until that version is explicitly
deleted (see Nos#deleteVersion(String, String, String)
.
If versioning is not enabled, this operation will overwrite an existing object with the same key; NOS will store the last write request. NOS does not provide object locking. If NOS receives multiple write requests for the same object nearly simultaneously, all of the objects might be stored. However, a single object will be stored with the final write request.
When specifying a location constraint when creating a bucket, all objects added to the bucket are stored in the bucket's region. For example, if specifying a Europe (EU) region constraint for a bucket, all of that bucket's objects are stored in the EU region.
putObject
in interface Nos
putObjectRequest
- The request object containing all the parameters to upload a
new object to NOS.PutObjectResult
object containing the information
returned by NOS for the newly created object.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointNos.putObject(String, String, File)
,
Nos.putObject(String, String, InputStream, ObjectMetadata)
public void putObjectMeta(String bucketName, String key, ObjectMetadata metadata) throws ClientException, ServiceException
putObjectMeta
in interface Nos
ClientException
ServiceException
public void copyObject(String sourceBucketName, String sourceKey, String destinationBucketName, String destinationKey) throws ClientException, ServiceException
Nos
Copies a source object to a new destination in NOS.
By default, all object metadata for the source object are copied to the
new destination object. The NOS AcccessControlList
(ACL) is
not copied to the new object; the new object will have the default
NOS ACL, CannedAccessControlList.Private
.
To copy an object, the caller's account must have read access to the source object and write access to the destination bucket
This method only exposes the basic options for copying an NOS object.
Additional options are available by calling the
copyObject(CopyObjectRequest)
method, including
conditional constraints for copying objects, setting ACLs, overwriting
object metadata, etc.
copyObject
in interface Nos
sourceBucketName
- The name of the bucket containing the source object to copy.sourceKey
- The key in the source bucket under which the source object is
stored.destinationBucketName
- The name of the bucket in which the new object will be
created. This can be the same name as the source bucket's.destinationKey
- The key in the destination bucket under which the new object
will be created.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointcopyObject(CopyObjectRequest)
public void copyObject(CopyObjectRequest copyObjectRequest) throws ClientException, ServiceException
Nos
Copies a source object to a new destination in NOS.
By default, all object metadata for the source object are copied to the
new destination object, unless new object metadata in the specified
CopyObjectRequest
is provided.
The NOS Acccess Control List (ACL) is not copied to the new
object. The new object will have the default NOS ACL,
CannedAccessControlList.Private
, unless one is explicitly
provided in the specified CopyObjectRequest
.
To copy an object, the caller's account must have read access to the source object and write access to the destination bucket.
This method exposes all the advanced options for copying an NOS object.
For simple needs, use the
copyObject(String, String, String, String)
method.
copyObject
in interface Nos
copyObjectRequest
- The request object containing all the options for copying an
NOS object.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointcopyObject(String, String, String, String)
public void moveObject(String sourceBucketName, String sourceKey, String destinationBucketName, String destinationKey) throws ClientException, ServiceException
Nos
move a source object to a new destination in NOS.
To move an object, the caller's account must have read access to the source object and write access to the destination bucket
moveObject
in interface Nos
sourceBucketName
- The name of the bucket containing the source object to move.sourceKey
- The key in the source bucket under which the source object is
stored.destinationBucketName
- The name of the bucket in which the new object will be
created. This can be the same name as the source bucket's.destinationKey
- The key in the destination bucket under which the new object
will be created.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointpublic void moveObject(MoveObjectRequest moveObjectRequest) throws ClientException, ServiceException
Nos
move a source object to a new destination in NOS.
To move an object, the caller's account must have read access to the source object and write access to the destination bucket
moveObject
in interface Nos
moveObjectRequest
- The request object containing all the options for moving an
NOS object.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointpublic void mediaSaveAsObject(String sourceBucketName, String sourceKey, String destinationBucketName, String destinationKey, String mediaOperation)
public void mediaSaveAsObject(MediaSaveAsRequest mediaSaveAsRequest)
public void deleteObject(String bucketName, String key) throws ClientException, ServiceException
Nos
Deletes the specified object in the specified bucket. Once deleted, the object can only be restored if versioning was enabled when the object was deleted.
If attempting to delete an object that does not exist, NOS returns a success message instead of an error message.
deleteObject
in interface Nos
bucketName
- The name of the NOS bucket containing the object to delete.key
- The key of the object to delete.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointdeleteObject(DeleteObjectRequest)
public void deleteObject(DeleteObjectRequest deleteObjectRequest) throws ClientException, ServiceException
Nos
Deletes the specified object in the specified bucket. Once deleted, the object can only be restored if versioning was enabled when the object was deleted.
If attempting to delete an object that does not exist, NOS will return a success message instead of an error message.
deleteObject
in interface Nos
deleteObjectRequest
- The request object containing all options for deleting an NOS
object.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointdeleteObject(String, String)
public DeleteObjectsResult deleteObjects(DeleteObjectsRequest deleteObjectsRequest)
Nos
In some cases, some objects will be successfully deleted, while some
attempts will cause an error. If any object in the request cannot be
deleted, this method throws a MultiObjectDeleteException
with
details of the error.
deleteObjects
in interface Nos
deleteObjectsRequest
- The request object containing all options for deleting
multiple objects.public URL generatePresignedUrl(String bucketName, String key, Date expiration) throws ClientException
Nos
Returns a pre-signed URL for accessing an NOS resource.
Pre-signed URLs allow clients to form a URL for an NOS resource, and then sign it with the current security credentials. The pre-signed URL can be shared to other users, allowing access to the resource without providing an account's security credentials.
Pre-signed URLs are useful in many situations where security credentials aren't available from the client that needs to make the actual request to NOS.
For example, an application may need remote users to upload files to the application owner's NOS bucket, but doesn't need to ship the security credentials with the application. A pre-signed URL to PUT an object into the owner's bucket can be generated from a remote location with the owner's security credentials, then the pre-signed URL can be passed to the end user's application to use.
generatePresignedUrl
in interface Nos
bucketName
- The name of the bucket containing the desired object.key
- The key in the specified bucket under which the desired object
is stored.expiration
- The time at which the returned pre-signed URL will expire.ClientException
- If there were any problems pre-signing the request for the
specified NOS object.Nos.generatePresignedUrl(String, String, Date, HttpMethod)
,
Nos.generatePresignedUrl(GeneratePresignedUrlRequest)
public URL generatePresignedUrl(String bucketName, String key, Date expiration, HttpMethod method) throws ClientException
Nos
Returns a pre-signed URL for accessing an NOS resource.
Pre-signed URLs allow clients to form a URL for an NOS resource, and then sign it with the current security credentials. The pre-signed URL can be shared to other users, allowing access to the resource without providing an account's security credentials.
Pre-signed URLs are useful in many situations where security credentials aren't available from the client that needs to make the actual request to NOS.
For example, an application may need remote users to upload files to the application owner's NOS bucket, but doesn't need to ship the security credentials with the application. A pre-signed URL to PUT an object into the owner's bucket can be generated from a remote location with the owner's security credentials, then the pre-signed URL can be passed to the end user's application to use.
generatePresignedUrl
in interface Nos
bucketName
- The name of the bucket containing the desired object.key
- The key in the specified bucket under which the desired object
is stored.expiration
- The time at which the returned pre-signed URL will expire.method
- The HTTP method verb to use for this URLClientException
- If there were any problems pre-signing the request for the
specified NOS object.Nos.generatePresignedUrl(String, String, Date)
,
Nos.generatePresignedUrl(GeneratePresignedUrlRequest)
public URL generatePresignedUrl(GeneratePresignedUrlRequest generatePresignedUrlRequest) throws ClientException
Nos
Returns a pre-signed URL for accessing an NOS resource.
Pre-signed URLs allow clients to form a URL for an NOS resource, and then sign it with the current security credentials. The pre-signed URL can be shared to other users, allowing access to the resource without providing an account's security credentials.
Pre-signed URLs are useful in many situations where security credentials aren't available from the client that needs to make the actual request to NOS.
For example, an application may need remote users to upload files to the application owner's NOS bucket, but doesn't need to ship the security credentials with the application. A pre-signed URL to PUT an object into the owner's bucket can be generated from a remote location with the owner's security credentials, then the pre-signed URL can be passed to the end user's application to use.
Note that presigned URLs cannot be used to upload an object with an attached policy, as described in this blog post. That method is only suitable for POSTs from HTML forms by browsers.
generatePresignedUrl
in interface Nos
generatePresignedUrlRequest
- The request object containing all the options for generating a
pre-signed URL (bucket name, key, expiration date, etc).ClientException
- If there were any problems pre-signing the request for the
NOS resource.Nos.generatePresignedUrl(String, String, Date)
,
Nos.generatePresignedUrl(String, String, Date, HttpMethod)
public void abortMultipartUpload(AbortMultipartUploadRequest abortMultipartUploadRequest) throws ClientException, ServiceException
Nos
abortMultipartUpload
in interface Nos
abortMultipartUploadRequest
- The AbortMultipartUploadRequest object that specifies all the
parameters of this operation.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointpublic CompleteMultipartUploadResult completeMultipartUpload(CompleteMultipartUploadRequest completeMultipartUploadRequest) throws ClientException, ServiceException
Nos
You first upload all parts using the
Nos.uploadPart(UploadPartRequest)
method. After successfully
uploading all individual parts of an upload, you call this operation to
complete the upload. Upon receiving this request, NOS concatenates all
the parts in ascending order by part number to create a new object. In
the CompleteMultipartUpload request, you must provide the parts list. For
each part in the list, you provide the part number and the ETag header
value, returned after that part was uploaded.
Processing of a CompleteMultipartUpload request may take several minutes to complete.
completeMultipartUpload
in interface Nos
completeMultipartUploadRequest
- The CompleteMultipartUploadRequest object that specifies all
the parameters of this operation.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointpublic InitiateMultipartUploadResult initiateMultipartUpload(InitiateMultipartUploadRequest initiateMultipartUploadRequest) throws ClientException, ServiceException
Nos
Nos.uploadPart(UploadPartRequest)
requests. You also include this
upload ID in the final request to either complete, or abort the multipart
upload request.initiateMultipartUpload
in interface Nos
initiateMultipartUploadRequest
- The InitiateMultipartUploadRequest object that specifies all
the parameters of this operation.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointpublic MultipartUploadListing listMultipartUploads(ListMultipartUploadsRequest listMultipartUploadsRequest) throws ClientException, ServiceException
Nos
This operation returns at most 1,000 multipart uploads in the response by default. The number of multipart uploads can be further limited using the MaxUploads property on the request parameter. If there are additional multipart uploads that satisfy the list criteria, the response will contain an IsTruncated property with the value set to true. To list the additional multipart uploads use the KeyMarker and UploadIdMarker properties on the request parameters.
listMultipartUploads
in interface Nos
listMultipartUploadsRequest
- The ListMultipartUploadsRequest object that specifies all the
parameters of this operation.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server point.public PartListing listParts(ListPartsRequest listPartsRequest) throws ClientException, ServiceException
Nos
This method must include the upload ID, returned by the
Nos.initiateMultipartUpload(InitiateMultipartUploadRequest)
operation. This request returns a maximum of 1000 uploaded parts by
default. You can restrict the number of parts returned by specifying the
MaxParts property on the ListPartsRequest. If your multipart upload
consists of more parts than allowed in the ListParts response, the
response returns a IsTruncated field with value true, and a
NextPartNumberMarker property. In subsequent ListParts request you can
include the PartNumberMarker property and set its value to the
NextPartNumberMarker property value from the previous response.
listParts
in interface Nos
listPartsRequest
- The ListPartsRequest object that specifies all the parameters
of this operation.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointpublic UploadPartResult uploadPart(UploadPartRequest uploadPartRequest) throws ClientException, ServiceException
Nos
Your UploadPart request must include an upload ID and a part number. The upload ID is the ID returned by NOS in response to your Initiate Multipart Upload request. Part number can be any number between 1 and 10,000, inclusive. A part number uniquely identifies a part and also defines its position within the object being uploaded. If you upload a new part using the same part number that was specified in uploading a previous part, the previously uploaded part is overwritten.
To ensure data is not corrupted traversing the network, specify the Content-MD5 header in the Upload Part request. NOS checks the part data against the provided MD5 value. If they do not match, NOS returns an error.
When you upload a part, the returned UploadPartResult contains an ETag property. You should record this ETag property value and the part number. After uploading all parts, you must send a CompleteMultipartUpload request. At that time NOS constructs a complete object by concatenating all the parts you uploaded, in ascending order based on the part numbers. The CompleteMultipartUpload request requires you to send all the part numbers and the corresponding ETag values.
uploadPart
in interface Nos
uploadPartRequest
- The UploadPartRequest object that specifies all the parameters
of this operation.ClientException
- If any errors are occured in the client point.ServiceException
- If any errors occurred in NOS server pointprotected <T> void presignRequest(Request<T> request, HttpMethod methodName, String bucketName, String key, Date expiration, String subResource)
request
- The request to sign.methodName
- The HTTP method (GET, PUT, DELETE, HEAD) for the specified request.bucketName
- The name of the bucket involved in the request. If the request is not an operation on a bucket this
parameter should be null.key
- The object key involved in the request. If the request is not an operation on an object, this
parameter should be null.expiration
- The time at which the signed request is no longer valid, and will stop working.subResource
- The optional sub-resource being requested as part of the request (e.g. "location", "acl", "logging",
or "torrent").protected static void populateRequestMetadata(Request<?> request, ObjectMetadata metadata)
Populates the specified request object with the appropriate headers from the ObjectMetadata
object.
request
- The request to populate with headers.metadata
- The metadata containing the header information to include in the request.protected <X extends WebServiceRequest> Request<X> createRequest(String bucketName, String key, X originalRequest, HttpMethodName httpMethod)
bucketName
- An optional parameter indicating the name of the bucket containing the resource involved in the
request.key
- An optional parameter indicating the key under which the desired resource is stored in the specified
bucket.originalRequest
- The original request, as created by the user.httpMethod
- The HTTP method to use when sending the request.public BucketLifecycleConfiguration getBucketLifecycleConfiguration(String bucketName) throws ClientException, ServiceException
Nos
getBucketLifecycleConfiguration
in interface Nos
bucketName
- The name of the bucket for which to retrieve lifecycle
configuration.ClientException
ServiceException
public void setBucketLifecycleConfiguration(String bucketName, BucketLifecycleConfiguration bucketLifecycleConfiguration) throws ClientException, ServiceException
Nos
setBucketLifecycleConfiguration
in interface Nos
bucketName
- The name of the bucket for which to set the lifecycle
configuration.bucketLifecycleConfiguration
- The new lifecycle configuration for this bucket, which
completely replaces any existing configuration.ClientException
ServiceException
public void setBucketLifecycleConfiguration(SetBucketLifecycleConfigurationRequest setBucketLifecycleConfigurationRequest) throws ClientException, ServiceException
Nos
setBucketLifecycleConfiguration
in interface Nos
setBucketLifecycleConfigurationRequest
- The request object containing all options for setting the
bucket lifecycle configuration.ClientException
ServiceException
public void deleteBucketLifecycleConfiguration(String bucketName) throws ClientException, ServiceException
Nos
deleteBucketLifecycleConfiguration
in interface Nos
bucketName
- The name of the bucket for which to remove the lifecycle
configuration.ClientException
ServiceException
public boolean validateStringSignature(String stringToSign, String signature)
public static void main(String[] args)
Copyright © 2017. All Rights Reserved.