Whatever message this page gives is out now! Go check it out!
component
{
this.name="S3_app";
void function onApplicationStart(){
application.awsCred = {
"alias" : "aws_std_queue",
"vendorName" : "AWS",
"region" : "us-east-2",
"secretAccessKey" : "xxxxxxxxxxxxxxxxx",
"accessKeyId" : "xxxxxxxxxxxxxxxx"
}
application.s3Conf = {
"serviceName" : "S3"
}
}
}application.s3Object = getCloudService(application.awsCred, application.s3Conf)<cfscript>
// define the credential and the configuration aliases in the ColdFusion Admin
application.s3=getCloudService("awsCred","s3Conf")
// code below.
...........
</cfscript><cfscript>
// Using credential alias and struct for service config
s3Conf = {
"alias":"s3Conf",
"serviceName" : "S3",
"clientOverrideConfig":{
"retryPolicy":{
"numRetries":4
}
},
"httpClientConfig":{
"maxConnections":50
}
}
application.s3= getCloudService("s3Cred", s3Conf)
// code below
.....................
</cfscript><cfscript>
// Using config alias and struct for service credentials
// s3 credentials
s3Creds={
"vendorName":"AWS",
"alias": "s3Cred",
"region":"us-east-2",
"accessKeyId": "access key",
"secretAccessKey": "secret access"
}
application.s3= getCloudService(s3Creds, "s3Conf")
// code below
.....................................
</cfscript><cfscript>
// Using Structs for both cloud credential and config
s3Cred={
"vendorName":"AWS",
"alias": "s3_cred_alias",
"region":"us-east-2",
"accessKeyId": "access key",
"secretAccessKey": "secret access key"
}
s3Conf = {
"alias":"s3_conf_alias",
"serviceName" : "S3",
"clientOverrideConfig":{
"retryPolicy":{
"numRetries":4
}
},
"httpClientConfig":{
"maxConnections":50
}
}
application.s3 = getCloudService(s3Cred, s3Conf )
// code below
...................................................................
</cfscript><cfscript>
// Create an object of administrator component and call the login method
adminObj = createObject("component","cfide.adminapi.administrator")
adminObj.login("admin")
// Create an object of cloud component
cloudObj = createObject("component","cfide.adminapi.cloud")
// define credentials struct
credentialStruct={
"alias" : "CredS3",
"vendorName" : "AWS",
"region" : "us-east-2",
"secretAccessKey" : "secret access key",
"accessKeyId" : "access key"
}
// add credential credentialStruct
try{
cloudObj.addCredential(credentialStruct)
writeOutput("Credentials added successfully")
}
catch(any e){
writeDump(e)
}
</cfscript><cfscript>
// Create an object of administrator component and call the login method
adminObj = createObject("component","cfide.adminapi.administrator")
adminObj.login("admin")
// Create an object of cloud component
cloudObj = createObject("component","cfide.adminapi.cloud")
// define configuration struct
configStruct={
"alias":"ConfS3",
"serviceName":"S3",
"clientOverrideConfig":{
"retryPolicy":{
"numRetries":4
}
},
"httpClientConfig":{
"maxConnections":50
}
}
// add config configStruct
try{
cloudObj.addServiceConfig(configStruct)
writeOutput("Configuration service added successfully")
}
catch(any e){
writeDump(e)
}
</cfscript>root(bucketname, createIfNotExists)Parameter | Description |
bucketName | The name of the bucket to be created. |
createIfNotExists | True or False. If the bucket doesn't exist, it gets created. |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
try{
storageService.root("bucket.001","true")
writeOutput("Bucket created successfully")
}
catch(any e){
writeDump(e)
}
</cfscript>createRoot(requestParameters)Parameter | Description |
bucketName | The name of the bucket to be created. |
objectLockEnabledForBucket | Yes or No. Identifies if object lock is enabled for the bucket. For more information, see Object locks. |
acl | Amazon S3 access control lists (ACLs) enable you to manage access to buckets and objects. Valid values are:
For more information, see ACLs in AWS. |
grant permission variables | Permissions that Amazon S3 supports in an ACL. Valid values are:
For more information, see Permissions. |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.002",
"objectLockEnabledForBucket" : true
}
// create a root
myobj=storageService.createRoot(createBucketRequest)
writeDump(myobj)
</cfscript>bucket(bucketName,createIfNotExists)Parameter | Description |
bucketName | The name of the bucket to be created. |
createIfNotExists | True or False. If the bucket doesn't exist, it gets created. |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
try{
storageService.bucket("bucket.002","true")
writeOutput("Bucket created successfully")
}
catch(any e){
writeDump(e)
}
</cfscript>createBucket(parameterStruct)Parameter | Description |
bucketName | The name of the bucket to be created. |
objectLockEnabledForBucket | Yes or No. Identifies if object lock is enabled for the bucket. For more information, see Object locks. |
acl | Amazon S3 access control lists (ACLs) enable you to manage access to buckets and objects. Valid values are:
For more information, see ACLs in AWS. |
grant permission variables | Permissions that Amazon S3 supports in an ACL. Valid values are:
For more information, see Permissions. |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// bucketList=storageService.listAll() // lists all buckets
// writeDump(bucketList)
// abort;
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.three.demo",
"objectLockEnabledForBucket" : true
}
// create a bucket
try{
myobj=storageService.createBucket(createBucketRequest)
writeOutput("Bucket created successfully")
writeDump(myobj)
}
catch (any e){
writeOutput("Failed to create the bucket")
writeDump(e)
}
</cfscript>delete(parameterStruct)delete(bucketName)Parameter | Description |
bucketName | The name of the bucket to delete. |
forcedDelete | True or False. Force deletes a bucket that has obejcts in it. |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.name",
"objectLockEnabledForBucket" : true
}
storageService.createBucket(createBucketRequest)
// delete the bucket
deleteBucketRequest = {
"bucket" : "bucket.name",
"forcedDelete" : "true" // default: false
}
try{
myobj=storageService.delete(deleteBucketRequest)
writeOutput("Bucket deleted successfully")
writeDump(myobj)
}
catch (any e){
writeOutput("Unable to delete the bucket")
writeDump(e)
}
</cfscript><cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
rootObj=storageService.bucket("bucket001","true")
try{
rootObj.delete("key")
writeOutput("Object created successfully")
}
catch(any e){
writeDump(e)
}
</cfscript><cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
//writeOutput(ExpandPath('./'))
// create a bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.name",
"objectLockEnabledForBucket" : true
}
bucketObj=storageService.createBucket(createBucketRequest)
// upload an object
uploadStruct = {
"srcFile" : "#ExpandPath('./')#/file.txt",
"key" : "key12",
"metadata":{
"place":"London",
"deployment":"Testing"
}
}
try{
deleteResponse=bucketObj.delete("key12")
writeOutput("Object deleted successfully")
writeDump(deleteResponse)
}
catch (any e){
writeOutput("Could not delete the object")
writeDump(e)
}
</cfscript>uploadFile(parameterStruct)| Parameter | Description | Required |
| srcFile | The path of the file that you want to upload in the bucket. | Yes |
| key | Unique identifier of the object. | Yes |
| acl | The ACL to apply to the object. For more information, see Canned ACL.The valid values are:
| No |
| cacheControl | Specify the caching behavior as defined here. | No |
| contentDisposition | Specify the content format of the object as defined here. | No |
| contentEncoding | Specify the type of encoding on the object as defined here. | No |
| contentLanguage | The language of the object that you want to upload. | No |
| contentLength | The size of the object in bytes. | No |
| validateContentMD5 | True or False. The base64-encoded 128-bit MD5 digest of the message (without the headers). | No |
| contentType | The format of the content as defined here. | No |
| expires | The date and time when the object cannot be cached any longer. | No |
| grantFullControl | Gives the grantee READ, READ_ACP, and WRITE_ACP permissions on the object. | No |
| grantRead | Allows grantee to only read the object data. | No |
| grantWrite | Allows grantee to write to the object data. | No |
| grantReadACP | Allows grantee to read the object ACL. | No |
| grantWriteACP | Allows grantee to write the ACL for the object. | No |
| metadata | The object metadata to use. | No |
| serverSideEncryption | The server-side encryption algorithm to be used. | No |
| storageClass | Valid values are:
For more information, see S3 storage class. | No |
| websiteRedirectLocation | If the bucket is configured as a website, specify the redirect request to another object in the same bucket or to an external URL. | No |
| sseCustomerAlgorithm | Specifies the algorithm to use to when encrypting the object. | No |
| sseCustomerKey | Specifies the customer-provided encryption key for S3 to use in encrypting data. | No |
| ssekmsKeyId | Specifies the ID of the AWS Key Management Service (AWS KMS). | No |
| ssekmsEncryptionContext | Specifies the AWS KMS Encryption Context to use for object encryption. | No |
| requestPayer | Confirms that the requester knows that they will be charged for the request. | No |
| tagging | The tag-set for the object. Must be a struct of key-value pairs. | No |
| objectLockMode | The Object locking mode that you want to apply to this object. Valid values are:
| No |
| objectLockRetainUntilDate | The date and time when you want this object's Object Lock to expire. | No |
| objectLockLegalHoldStatus | Indicates whether the specified object has a Legal Hold in place.. Valid values are:
| No |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
//writeOutput(ExpandPath('./'))
// create a bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.name",
"objectLockEnabledForBucket" : true
}
bucketObj=storageService.createBucket(createBucketRequest)
// upload an object
uploadStruct = {
"srcFile" : "#ExpandPath('./')#/file.txt",
"key" : "key12",
"metadata":{
"place":"London",
"deployment":"Testing"
}
}
try{
uploadResponse=bucketObj.uploadFile(uploadStruct)
writeOutput("Object uploaded successfully")
writeDump(uploadResponse)
}
catch (any e){
writeOutput("Could not upload the object")
writeDump(e)
}
</cfscript>downloadToFile(parameterStruct)| Parameter | Description | Required |
| destinationFile | The path of the file that that contains the object, which you want to download. | Yes |
| key | Unique identifier of the object. | Yes |
| cacheControl | Set the cache control header of the object, | No |
| contentDisposition | Set the Content-Disposition header of the response. | No |
| contentEncoding | Set the Content-Encoding header of the response. | No |
| contentLanguage | Set the Content-Language header of the response. | No |
| contentType | Set the Content-Type header of the response. | No |
| expires | Sets the Response header of the response. | No |
| versionId | Refer to a specific version of the object. | No |
| sseCustomerAlgorithm | Specify the algorithm to use to when encrypting the object. | No |
| sseCustomerKey | Specify the customer-provided encryption key for S3 to use in encrypting data. | No |
| requestPayer | Confirms that the requester knows that they will be charged for the request. | No |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.demo.four",
"objectLockEnabledForBucket" : true
}
bucketObj=storageService.createBucket(createBucketRequest)
// upload an object
uploadStruct = {
"srcFile" : "#ExpandPath('./')#/file.txt",
"key" : "key22",
"metadata":{
"filename":"file.txt",
"place":"bangalore",
"category":"finance"
}
}
bucketObj.uploadFile(uploadStruct)
// download the file
downloadStruct = {
"destinationFile" : "file.txt",
"key" : "key22"
}
try{
downloadResponse=bucketObj.downloadToFile(downloadStruct)
writeOutput("Object downloaded successfully")
writeDump(downloadResponse)
}
catch (any e){
writeOutput("Failed to download object")
writeDump(e)
}
</cfscript>listAll(parameterStruct)listAll()Parameter | Description |
delimiter | Character to group keys. |
encodingType | Encode the object keys in the response and specifies the encoding method to use. |
marker | Key to start with when listing objects in a bucket. |
maxKeys | The maximum number of keys returned in the response. |
prefix | Limits the response to keys that begin with the specified prefix. |
requestpayer | Confirms that the requester knows that he/she will be charged for the request. Valid value is REQUESTER. |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// lists all buckets
bucketList=storageService.listAll()
writeOutput("List of buckets")
writeDump(bucketList)
</cfscript>copy(parameterStruct)Parameter | Description | Required |
sourceBucket | The bucket from where you want to copy the object. | Yes |
sourceKey | The key associated with the object. | Yes |
sourceVersionId | The version id that was associated with the object. | No |
key | The destination key of the object. | Yes |
storageClass | For more information, see S3 storage class.. Valid value is: GLACIAR. | No |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create two buckets
createBucketRequest1 = {
"acl":"PRIVATE",
"bucket" : "cf.source.bucket.1",
"objectLockEnabledForBucket" : true
}
createBucketRequest2 = {
"acl":"PRIVATE",
"bucket" : "cf.dest.bucket.1",
"objectLockEnabledForBucket" : true
}
// source bucket
source_obj=storageService.createBucket(createBucketRequest1)
// destination bucket
dest_object=storageService.createBucket(createBucketRequest2)
// upload file struct
uploadStruct = {
"srcFile" : "#ExpandPath('./')#/file.txt",
"key" : "key12"
}
// upload file to source bucket
uploadResponse=source_obj.uploadFile(uploadStruct)
// copy file struct
copyRequest = {
"sourceBucket": "cf.source.bucket.1",
"sourceKey" : "key12",
"key" : "destKey"
}
copyResponse=dest_object.copy(copyRequest);
objList=dest_object.listAll()
writeDump(objList)
</cfscript>putPolicy(parameterStruct)Parameter | Description | Required |
confirmRemoveSelfBucketAccess | True or False. Set this parameter to true to confirm that you want to remove your permissions to change this bucket policy in the future. | No |
policy | The policy to be enforced for the bucket. For more information, see S3 policies. | No |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
bucketList=storageService.listAll()
//writeDump(bucketList)
rootObj=storageService.bucket("bucket.policy","true")
policy = {
"Id": "Policy1571390473326",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1574139965216",
"Action": [
"s3:GetBucketAcl"
],
"Effect": "Allow",
"Resource": "bucket.policy",
"Principal": "*"
}
]
}
policyRequest = {
"policy" : policy
}
rootObj.putPolicy(policyRequest);
writedump(rootObj.getPolicies())
</cfscript>deletePolicies()<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
bucketList=storageService.listAll()
//writeDump(bucketList)
rootObj=storageService.bucket("bucket.policy","true")
policy = {
"Id": "Policy1571390473326",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1574139965216",
"Action": [
"s3:GetBucketAcl"
],
"Effect": "Allow",
"Resource": "bucket.policy",
"Principal": "*"
}
]
}
policyRequest = {
"policy" : policy
}
rootObj.putPolicy(policyRequest);
writedump(rootObj.getPolicies())
// delete policy
deletePolicyResponse=rootObj.deletePolicies()
writeDump(deletePolicyResponse)
</cfscript>getPolicies()<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
bucketList=storageService.listAll()
//writeDump(bucketList)
rootObj=storageService.bucket("bucket.policy","true")
policy = {
"Id": "Policy1571390473326",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1574139965216",
"Action": [
"s3:GetBucketAcl"
],
"Effect": "Allow",
"Resource": "bucket.policy",
"Principal": "*"
}
]
}
policyRequest = {
"policy" : policy
}
rootObj.putPolicy(policyRequest);
writedump(rootObj.getPolicies())
// delete policy
deletePolicyResponse=rootObj.deletePolicies()
writeDump(deletePolicyResponse)
</cfscript>enableVersioning(parameterStruct)Parameter | Description | Required |
mfa | The combination of the authentication device's serial number, a space, and the value that is displayed on your authentication device. The format of the mfa is: "mfa":"arn:aws:iam::0123456789:mfa/username" | No |
mfaDelete | Specifies whether MFA delete is enabled in the bucket versioning configuration. Valid values are:
| No |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.demo.getstatus",
"objectLockEnabledForBucket" : true
}
// create a bucket
bucketObj=storageService.createBucket(createBucketRequest)
// enable versioning
bucketObj.enableVersioning()
// get version status
versionStatus=bucketObj.getVersioningStatus()
writeDump(versionStatus)
</cfscript>getVersioningStatus()<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.demo.getstatus",
"objectLockEnabledForBucket" : true
}
// create a bucket
bucketObj=storageService.createBucket(createBucketRequest)
// enable versioning
bucketObj.enableVersioning()
// get version status
versionStatus=bucketObj.getVersioningStatus()
writeDump(versionStatus)
</cfscript>listAllVersions(parameterStruct)Parameter | Description | Required |
delimiter | Character to group keys. | No |
encodingType | Requests Amazon S3 to encode the object keys in the response and specifies the encoding method to use. | No |
marker | The object version you want to start listing from. | No |
maxKeys | Sets the maximum number of keys returned in the response. | No |
prefix | Select only those keys that begin with the specified prefix. | No |
keyMarker | The key to start with when listing objects in a bucket. | No |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.demo.listversions",
"objectLockEnabledForBucket" : true
}
// create a bucket
myobj=storageService.createBucket(createBucketRequest)
// define file upload structs
uploadStruct1 = {
"srcFile" : "#ExpandPath('./')#/file1.txt",
"key" : "key1"
}
uploadStruct2 = {
"srcFile" : "#ExpandPath('./')#/file2.txt",
"key" : "key122"
}
uploadStruct3 = {
"srcFile" : "#ExpandPath('./')#/file3.txt",
"key" : "key123"
}
uploadStruct4 = {
"srcFile" : "#ExpandPath('./')#/file1.txt",
"key" : "key124"
}
uploadResponse1=myobj.uploadFile(uploadStruct1);
uploadResponse2=myobj.uploadFile(uploadStruct2);
uploadResponse3=myobj.uploadFile(uploadStruct3);
uploadResponse4=myobj.uploadFile(uploadStruct4);
listAllVersionsRequest={
"prefix" : "key12"
}
// list all versions
listVersion=myobj.listAllVersions(listAllVersionsRequest)
writeDump(listVersion)
</cfscript>suspendVersioning(parameterStruct)Parameter | Description | Required |
mfa | The combination of the authentication device's serial number, a space, and the value that is displayed on your authentication device. The format of the mfa is: "mfa":"arn:aws:iam::0123456789:mfa/username" | No |
mfaDelete | Specifies whether MFA delete is enabled or disabled. | No |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.demo.suspendversioning",
// to suspend versioning, turn off object locking for the bucket
"objectLockEnabledForBucket" : false
}
// create a bucket
myobj=storageService.createBucket(createBucketRequest)
// enable versioning on the bucket
myobj.enableVersioning();
// get the version status
versionStatus1=myobj.getVersioningStatus();
writeDump(versionStatus1)
// suspend the versioning
myobj.suspendVersioning();
versionStatus2=myobj.getVersioningStatus();
writeDump(versionStatus2)
</cfscript>putBucketAcl(parameterStruct)Parameter | Description | Required |
acl | Amazon S3 access control lists (ACLs) enable you to manage access to buckets and objects. Valid values are:
For more information, see ACLs in AWS. | No |
grant permission variables | Permissions that Amazon S3 supports in an ACL. Valid values are:
For more information, see Permissions. | No |
<cfscript>
storageService = getCloudService(this.s3Cred,this.s3Conf)
createBucketRequest1 = {
"bucket" : "cfqa.003"
}
rootObj = storageService.createRoot(createBucketRequest1);
putBucketAclRequest = {
"acl" : "PRIVATE"
}
putBucketAclResponse=rootObj.putBucketAcl(putBucketAclRequest);
writeDump(putBucketAclResponse)
</cfscript><cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
createBucketRequest1 = {
"bucket" : "cfqa.003"
}
rootObj = storageService.createRoot(createBucketRequest1)
putBucketAclRequest = {
"grantFullControl": "emailAddress=john@example.com",
// "grantFullControl": "id=f1db27629293ee8354a2874de1959b39bec20ffe98417b931fb381f97007cf97"
"grantReadACP" : "uri=http://acs.amazonaws.com/groups/s3/LogDelivery"
}
putBucketAclResponse=rootObj.putBucketAcl(putBucketAclRequest);
writeDump(putBucketAclResponse)
</cfscript>getBucketAcl()<cfscript>
storageService = getCloudService(this.s3Cred,this.s3Conf)
createBucketRequest1 = {
"bucket" : "cfqa.004",
"grantFullControl": "uri=http://acs.amazonaws.com/groups/global/AuthenticatedUsers"
}
rootObj = storageService.createRoot(createBucketRequest1);
getBucketAclResponse=rootObj.getBucketAcl()
writeDump(getBucketAclResponse)
</cfscript>putObjectAcl(parameterStruct)Parameter | Description | Required |
acl | Amazon S3 access control lists (ACLs) enable you to manage access to buckets and objects. Valid values are:
For more information, see ACLs in AWS. | No |
grant permission variables | Permissions that Amazon S3 supports in an ACL. Valid values are:
For more information, see Permissions. | No |
key | The key for the operation. | Yes |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"bucket" : "bucket.putobjectacl.demo"
}
bucketObj = storageService.createBucket(createBucketRequest)
// upload an object
uploadStruct = {
"srcFile" : "#ExpandPath('./')#/s3-notes.pdf",
"key" : "key12"
}
bucketObj.uploadFile(uploadStruct)
// put ACL on the object
putObjectAclRequest = {
"key" : "key12",
"acl" : "PRIVATE"
}
try{
objectAclResponse=bucketObj.putObjectAcl(putObjectAclRequest)
writeOutput("ACL applied successfully on the object")
writeDump(objectAclResponse)
}
catch(any e){
writeOutput("Unable to apply ACL on the object")
writeDump(e)
}
putObjectAclResponse=bucketObj.GetObjectAcl("key12")
writeDump(putObjectAclResponse)
</cfscript>getObjectAcl(parameterStruct)Parameter | Description | Required |
key | The key of the object for which to get the ACL information. | Yes |
versionId | Refer to a specific version of the object. | No |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"bucket" : "bucket.putobjectacl.demo"
}
bucketObj = storageService.createBucket(createBucketRequest)
// upload an object
uploadStruct = {
"srcFile" : "#ExpandPath('./')#/s3-notes.pdf",
"key" : "key12"
}
bucketObj.uploadFile(uploadStruct)
// put ACL on the object
putObjectAclRequest = {
"key" : "key12",
"acl" : "PRIVATE"
}
try{
objectAclResponse=bucketObj.putObjectAcl(putObjectAclRequest)
writeOutput("ACL applied successfully on the object")
writeDump(objectAclResponse)
}
catch(any e){
writeOutput("Unable to apply ACL on the object")
writeDump(e)
}
putObjectAclResponse=bucketObj.getObjectAcl("key12")
writeDump(putObjectAclResponse)
</cfscript>"rules" :
[
{
"id" : "rule1",
"prefix" : "a/b",
"lifecycleRuleFilter" :
{
"prefix" : "",
"tagging" :
{
"key": "",
"value" : ""
},
"lifecycleRuleAndOperator" :
{
"prefix" : "",
"tagging" :
[{
"key": "",
"value" : ""
}]
}
},
"status" : "ENABLED",
"expiration" :
{
"date" : "YYYY-MM-DD",
"days" : 3
},
"noncurrentVersionExpirationDays" : 30,
"noncurrentVersionTransitions" :
[ {
"days" : 35,
"storageClass" : "GLACIER"
}],
"abortIncompleteMultipartUploadInDays" : 7,
"transitions" : [
{
"days" : 90,
"storageClass" : "ONEZONE_IA"
}
]
}
]"lifecycleRuleFilter" :
{
"prefix" : "",
"tagging" :
{
"key": "",
"value" : ""
},
"lifecycleRuleAndOperator" :
{
"prefix" : "",
"tagging" :
[{
"key": "",
"value" : ""
}]
}
}<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
deleteStruct = {
"bucket" : "bucket.rule.append1",
"forcedDelete" : "true"
}
// Adding lifecycle rules by specifying date
// create a bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.rule.four",
"objectLockEnabledForBucket" : true
}
bucketObj=storageService.createBucket(createBucketRequest)
// upload an object to the bucket
uploadStruct={
"srcFile":"#ExpandPath('./')#/s3-notes.pdf",
"key":"key114"
}
bucketObj.uploadFile(uploadStruct)
exp_date=DateFormat(DateAdd("d",8,now()),"yyyy-mm-dd")
trans_date=DateFormat(DateAdd("d",2,now()),"yyyy-mm-dd")
ruleStruct = {
"rules" :
[{
"id" : "rule1",
"prefix":"key",
"status" : "ENABLED",
"expiration" : {
"date":exp_date
},
"transitions" :
[{
"date":trans_date,
"storageClass" : "ONEZONE_IA"
}]
}]
}
try{
bucketObj.setRules(ruleStruct)
writeOutput("Lifecycle rule set successfully")
rules=bucketObj.getRules().rules
writedump(rules)
}
catch(any e){
writeOutput("Unable to set lifecycle")
writeDump(e)
}
</cfscript><cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.rule.three",
"objectLockEnabledForBucket" : true
}
bucketObj=storageService.createBucket(createBucketRequest)
// upload an object to the bucket
uploadStruct={
"srcFile":"#ExpandPath('./')#/s3-notes.pdf",
"key":"key112"
}
bucketObj.uploadFile(uploadStruct)
ruleStruct={
"rules":[{
"id" : "rule1",
"prefix":"key",
"status" : "ENABLED",
"noncurrentVersionTransitions" :
[{
"days":30,
"storageClass" : "INTELLIGENT_TIERING"
}]
}]
}
try{
bucketObj.setRules(ruleStruct)
writeOutput("Lifecycle rule set successfully")
//writeDump(setRuleResponse)
// rules=bucketObj.getRules().rules
// writedump(rules)
}
catch(any e){
writeOutput("Unable to set lifecycle")
writeDump(e)
}
</cfscript>"rules" :
[
{
"id" : "rule1",
"prefix" : "a/b",
"lifecycleRuleFilter" :
{
"prefix" : "",
"tagging" :
{
"key": "",
"value" : ""
},
"lifecycleRuleAndOperator" :
{
"prefix" : "",
"tagging" :
[{
"key": "",
"value" : ""
}]
}
},
"status" : "ENABLED",
"expiration" :
{
"date" : "YYYY-MM-DD",
"days" : 3
},
"noncurrentVersionExpirationDays" : 30,
"noncurrentVersionTransitions" :
[ {
"days" : 35,
"storageClass" : "GLACIER"
}],
"abortIncompleteMultipartUploadInDays" : 7,
"transitions" : [
{
"days" : 90,
"storageClass" : "ONEZONE_IA"
}
]
}
]"lifecycleRuleFilter" :
{
"prefix" : "",
"tagging" :
{
"key": "",
"value" : ""
},
"lifecycleRuleAndOperator" :
{
"prefix" : "",
"tagging" :
[{
"key": "",
"value" : ""
}]
}
}<cfscript>
storageService = getCloudService(this.s3Cred,this.s3Conf)
rules={
"rules" : [
{
"id" : "rule1",
"prefix" : "a/b",
"status" : "ENABLED",
"expiration" : {
//"date" : "DD/MM/YYY",
"days" : 3
},
"noncurrentVersionExpirationDays" : 30,
"noncurrentVersionTransitions" :[ {
"days" : 35,
"storageClass" : "GLACIER"
}],
"abortIncompleteMultipartUploadInDays" : 7,
"transitions" : [
{
"days" : 90,
"storageClass" : "ONEZONE_IA"
}
]
}
]
}
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "cf.bucket",
"objectLockEnabledForBucket" : true
}
rootObj=storageService.createBucket(createBucketRequest)
appendRulesResponse=rootObj.appendRules(rules)
writeDump(appendRulesResponse)
</cfscript><cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.rule.delete",
"objectLockEnabledForBucket" : true
}
bucketObj=storageService.createBucket(createBucketRequest)
// upload an object to the bucket
uploadStruct={
"srcFile":"#ExpandPath('./')#/s3-notes.pdf",
"key":"key100"
}
bucketObj.uploadFile(uploadStruct)
// create rule
ruleStruct={
"rules":[{
"id" : "rule1",
"prefix":"key",
"status" : "ENABLED",
"noncurrentVersionTransitions" :
[{
"days":30,
"storageClass" : "INTELLIGENT_TIERING"
}]
}]
}
// set the rule
bucketObj.setRules(ruleStruct)
// get the rule
rules=bucketObj.getRules().rules
writeDump(rules)
</cfscript>addTags(parameterStruct)Parameter | Description | Required |
key | Unique identifier of the object. | Yes |
versionId | Refer to a specific version of the object. | No |
tags | Array of tag structs. | Yes |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.demoaddtagstest",
"objectLockEnabledForBucket" : true
}
bucketobj=storageService.createBucket(createBucketRequest)
// upload a file
uploadStruct = {
"srcFile" : "#ExpandPath('./')#/s3-notes.pdf",
"key" : "key12"
}
bucketobj.uploadFile(uploadStruct)
// add tags to the object
addTagStruct={
"key" : "key12",
"tags" : [
{
"key" : "label",
"value" : "red"
},
{
"key": "category",
"value": "important"
}
]
}
try{
addTagResponse=bucketobj.addTags(addTagStruct)
writeOutput("Tags added successfully")
writeDump(addTagResponse)
}
catch(any e){
writeOutput("Failed to add tags")
writeDump(e)
}
</cfscript>getTagObjects(parameterStruct)Parameter | Description | Required |
key | Unique identifier of the object. | Yes |
versionId | Refer to a specific version of the object. | No |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.demoaddtagstest",
"objectLockEnabledForBucket" : true
}
bucketobj=storageService.createBucket(createBucketRequest)
// upload a file
uploadStruct = {
"srcFile" : "#ExpandPath('./')#/s3-notes.pdf",
"key" : "key12"
}
bucketobj.uploadFile(uploadStruct)
// add tags to the object
addTagStruct={
"key" : "key12",
"versionId":"v1",
"tags" : [
{
"key" : "label",
"value" : "red"
},
{
"key": "category",
"value": "important"
}
]
}
getTagResponse=bucketobj.GettagObjects("key12")
writeDump(getTagResponse)
</cfscript>getObjectDetails(parameterStruct)| Parameter | Description | Required |
| srcFile | The path of the file that you want to upload in the bucket. | Yes |
| key | Unique identifier of the object. | Yes |
| acl | The ACL to apply to the object. For more information, see Canned ACL.The valid values are:
| No |
| cacheControl | Specify the caching behavior as defined here. | No |
| contentDisposition | Specify the content format of the object as defined here. | No |
| contentEncoding | Specify the type of encoding on the object as defined here. | No |
| contentLanguage | The language of the object that you want to upload. | No |
| contentLength | The size of the object in bytes. | No |
| validateContentMD5 | True or False. The base64-encoded 128-bit MD5 digest of the message (without the headers). | No |
| contentType | The format of the content as defined here. | No |
| expires | The date and time when the object cannot be cached any longer. | No |
| grantFullControl | Gives the grantee READ, READ_ACP, and WRITE_ACP permissions on the object. | No |
| grantRead | Allows grantee to only read the object data. | No |
| grantWrite | Allows grantee to write to the object data. | No |
| grantReadACP | Allows grantee to read the object ACL. | No |
| grantWriteACP | Allows grantee to write the ACL for the object. | No |
| metadata | The object metadata to use. | No |
| serverSideEncryption | The server-side encryption algorithm to be used. | No |
| storageClass | Valid values are:
For more information, see S3 storage class. | No |
| websiteRedirectLocation | If the bucket is configured as a website, specify the redirect request to another object in the same bucket or to an external URL. | No |
| sseCustomerAlgorithm | Specifies the algorithm to use to when encrypting the object. | No |
| sseCustomerKey | Specifies the customer-provided encryption key for S3 to use in encrypting data. | No |
| ssekmsKeyId | Specifies the ID of the AWS Key Management Service (AWS KMS). | No |
| ssekmsEncryptionContext | Specifies the AWS KMS Encryption Context to use for object encryption. | No |
| requestPayer | Confirms that the requester knows that they will be charged for the request. | No |
| tagging | The tag-set for the object. Must be a struct of key-value pairs. | No |
| objectLockMode | The Object locking mode that you want to apply to this object. Valid values are:
| No |
| objectLockRetainUntilDate | The date and time when you want this object's Object Lock to expire. | No |
| objectLockLegalHoldStatus | Indicates whether the specified object has a Legal Hold in place.. Valid values are:
| No |
<cfscript>
storageService = getcloudService(application.awsCred,application.s3Conf)
// create a bucket
bucketStruct={
"acl":"PRIVATE",
"bucket" : "bucket.demo.objectdetailsdemo",
"objectLockEnabledForBucket" : true
}
bucketObj=storageService.createBucket(bucketStruct)
// upload an object into the bucket
uploadStruct = {
"srcFile" : "#ExpandPath('./')#/Colors.jpg",
"key" : "key001",
"metadata": {
"filename": "Colors.jpg",
"creator":"john",
"place":"london",
"creation_date":"2020/04/20",
"filetype":"image"
},
"contentLanguage":"en",
"websiteRedirectLocation":"http://bucket",
"expires":"2020-05-28"
}
bucketObj.uploadFile(uploadStruct)
// get object details
objectDetailsResponse=bucketObj.getObjectDetails("key001")
writeDump(objectDetailsResponse)
</cfscript>parallelUploadFile(parameterStruct)| Parameter | Description | Required |
| srcFile | The location of the file that you want to upload. | Yes |
| chunkLengthInBytes | Size of the content chunk. | No |
| timeOutInSeconds | The time out of the upload operation. | No |
| acl | Amazon S3 access control lists (ACLs) enable you to manage access to buckets and objects. Valid values are:
| No |
| cacheControl | Specify the caching behavior as defined here. | No |
| contentDisposition | Specify the content format of the object as defined here. | No |
| contentEncoding | Specify the type of encoding on the object as defined here. | No |
| contentLanguage | The language of the object that you want to upload. | No |
| contentLength | The size of the object in bytes. | No |
| validateContentMD5 : | True | False. The base64-encoded 128-bit MD5 digest of the message (without the headers). | No |
| contentType | The format of the content as defined here. | No |
| expires | The date and time when the object cannot be cached any longer. | No |
| grantFullControl | Gives the grantee READ, READ_ACP, and WRITE_ACP permissions on the object. | No |
| grantRead | Allows grantee to read the object ACL. | No |
| grantReadACP | Allows grantee to read the object ACL. | No |
| grantWriteACP | Allows grantee to write the ACL for the object. | No |
| metadata | The object metadata to use. | No |
| serverSideEncryption | The server-side encryption algorithm to be used. | No |
| storageClass | Valid values are:
For more information, see S3 storage class. | No |
| websiteRedirectLocation | If the bucket is configured as a website, specify the redirect request to another object in the same bucket or to an external URL. | No |
| sseCustomerAlgorithm | Specifies the algorithm to use to when encrypting the object. | No |
| sseCustomerKey | Specifies the customer-provided encryption key for S3 to use in encrypting data. | No |
| sseCustomerKeyMD5 | Specifies the MD5 of the key. | No |
| ssekmsKeyId | Specifies the ID of the AWS Key Management Service (AWS KMS). | No |
| ssekmsEncryptionContext | Specifies the AWS KMS Encryption Context to use for object encryption. | No |
| requestPayer | Confirms that the requester knows that they will be charged for the request. | No |
| tagging | NOTE: This will be supported from s3 sdk 2.10.46 onwards. | No |
| objectLockMode | The Object locking mode that you want to apply to this object. Valid values are:
| |
| objectLockRetainUntilDate | The date and time when you want this object's Object Lock to expire. | No |
| objectLockLegalHoldStatus | Indicates whether the specified object has a Legal Hold in place.. Valid values are:
| No |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"bucket" : "bucket.parallel.upload"
}
rootObj = storageService.createBucket(createBucketRequest)
// parallel upload struct
parallelUploadRequest = {
"srcFile" : "#ExpandPath('..')#/files/file.txt",
"chunkLengthInBytes": "5e+6",
"timeOutInSeconds": "60",
"key": "key1"
}
try{
uploadResponse = rootObj.parallelUploadFile(parallelUploadRequest)
writeOutput("Parallel upload successful")
writeDump(uploadResponse)
}
catch(any e){
writeDump(e)
}
</cfscript>parallelDownloadFile(parameterStruct)| Parameter | Description | Required |
| key | The key with which an object was uploaded. | Yes |
| destinationFile | The location where you want to download the file to. | Yes |
| chunkLengthInBytes | Size of the content chunk. | No |
| cacheControl | Set the cache control header of the object, | No |
| contentDisposition | Set the Content-Disposition header of the response. | No |
| contentEncoding | Set the Content-Encoding header of the response. | No |
| contentLanguage | Set the Content-Language header of the response. | No |
| contentType | Set the Content-Type header of the response. | No |
| expires | Sets the Response header of the response. | No |
| versionId | Refer to a specific version of the object. | No |
| sseCustomerAlgorithm | Specify the algorithm to use to when encrypting the object. | No |
| sseCustomerKey | Specify the customer-provided encryption key for S3 to use in encrypting data. | No |
| requestPayer | Confirms that the requester knows that they will be charged for the request. | No |
<cfscript>
storageService = cloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"bucket" : "bucket.parallel.download"
}
rootObj = storageService.createBucket(createBucketRequest)
// parallel upload struct
parallelUploadRequest = {
"srcFile" : "#ExpandPath('..')#/files/file.txt",
"chunkLengthInBytes": "5e+6",
"timeOutInSeconds": "60",
"key": "key1"
}
// upload object parallelly
rootObj.parallelUploadFile(parallelUploadRequest)
// parallel download struct
parallelDownloadRequest = {
"key" : "key1",
"destinationFile" : "file.txt",
"chunkLengthInBytes": "5e+6"
}
downloadResponse=rootObj.parallelDownloadFile(parallelDownloadRequest)
writeDump(downloadResponse)
</cfscript>multipartUpload(parameterStruct)| Parameter | Description | Required |
| srcFile | The location of the file that you want to upload. | Yes |
| chunkLengthInBytes | Size of the content chunk. | No |
| timeOutInSeconds | The time out of the upload operation. | No |
| acl | Amazon S3 access control lists (ACLs) enable you to manage access to buckets and objects. Valid values are:
| No |
| cacheControl | Specify the caching behavior as defined here. | No |
| contentDisposition | Specify the content format of the object as defined here. | No |
| contentEncoding | Specify the type of encoding on the object as defined here. | No |
| contentLanguage | The language of the object that you want to upload. | No |
| contentLength | The size of the object in bytes. | No |
| validateContentMD5 : | True | False. The base64-encoded 128-bit MD5 digest of the message (without the headers). | No |
| contentType | The format of the content as defined here. | No |
| expires | The date and time when the object cannot be cached any longer. | No |
| grantFullControl | Gives the grantee READ, READ_ACP, and WRITE_ACP permissions on the object. | No |
| grantRead | Allows grantee to read the object ACL. | No |
| grantReadACP | Allows grantee to read the object ACL. | No |
| grantWriteACP | Allows grantee to write the ACL for the object. | No |
| metadata | The object metadata to use. | No |
| serverSideEncryption | The server-side encryption algorithm to be used. | No |
| storageClass | Valid values are:
For more information, see S3 storage class. | No |
| websiteRedirectLocation | If the bucket is configured as a website, specify the redirect request to another object in the same bucket or to an external URL. | No |
| sseCustomerAlgorithm | Specifies the algorithm to use to when encrypting the object. | No |
| sseCustomerKey | Specifies the customer-provided encryption key for S3 to use in encrypting data. | No |
| sseCustomerKeyMD5 | Specifies the MD5 of the key. | No |
| ssekmsKeyId | Specifies the ID of the AWS Key Management Service (AWS KMS). | No |
| ssekmsEncryptionContext | Specifies the AWS KMS Encryption Context to use for object encryption. | No |
| requestPayer | Confirms that the requester knows that they will be charged for the request. | No |
| tagging | NOTE: This will be supported from s3 sdk 2.10.46 onwards. | No |
| objectLockMode | The Object locking mode that you want to apply to this object. Valid values are:
| |
| objectLockRetainUntilDate | The date and time when you want this object's Object Lock to expire. | No |
| objectLockLegalHoldStatus | Indicates whether the specified object has a Legal Hold in place.. Valid values are:
| No |
<cfscript>
storageService = cloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"bucket" : "bucket.parallel.multipartupload"
}
rootObj = storageService.createBucket(createBucketRequest)
// multi part upload struct
mulitipartUploadRequest = {
"srcFile" : "#ExpandPath('..')#/files/file.mp4",
"chunkLengthInBytes": "5e+6",
"timeOutInSeconds": "2",
"key": "key1"
}
try{
uploadResponse = rootObj.multipartUpload(mulitipartUploadRequest)
writeOutput("File uploaded sucessfully in multiple parts")
writeDump(uploadResponse)
}
catch(any e){
writeDump(e)
}
</cfscript>uploadObject(parameterStruct)| Parameter | Description | Required |
| key | Unique identifier of the object. | Yes |
| acl | The ACL to apply to the object. For more information, see Canned ACL.The valid values are:
| No |
| cacheControl | Specify the caching behavior as defined here. | No |
| contentDisposition | Specify the content format of the object as defined here. | No |
| contentEncoding | Specify the type of encoding on the object as defined here. | No |
| contentLanguage | The language of the object that you want to upload. | No |
| contentLength | The size of the object in bytes. | No |
| validateContentMD5 | The base64-encoded 128-bit MD5 digest of the message (without the headers). | No |
| contentType | The format of the content as defined here. | No |
| expires | The date and time when the object cannot be cached any longer. | No |
| grantFullControl | Gives the grantee READ, READ_ACP, and WRITE_ACP permissions on the object. | No |
| grantRead | Allows grantee to only read the object data. | No |
| grantWrite | Allows grantee to write to the object data. | No |
| grantReadACP | Allows grantee to read the object ACL. | No |
| grantWriteACP | Allows grantee to write the ACL for the object. | No |
| metadata | The object metadata to use. | No |
| serverSideEncryption | The server-side encryption algorithm to be used. | No |
| storageClass | Valid values are:
For more information, see S3 storage class. | No |
| websiteRedirectLocation | If the bucket is configured as a website, specify the redirect request to another object in the same bucket or to an external URL. | No |
| sseCustomerAlgorithm | Specifies the algorithm to use to when encrypting the object. | No |
| sseCustomerKey | Specifies the customer-provided encryption key for S3 to use in encrypting data. | No |
| ssekmsKeyId | Specifies the ID of the AWS Key Management Service (AWS KMS). | No |
| ssekmsEncryptionContext | Specifies the AWS KMS Encryption Context to use for object encryption. | No |
| requestPayer | Confirms that the requester knows that they will be charged for the request. | No |
| tagging | The tag-set for the object. Must be a struct of key-value pairs. | No |
| objectLockMode | The Object locking mode that you want to apply to this object. Valid values are:
| No |
| objectLockRetainUntilDate | The date and time when you want this object's Object Lock to expire. | No |
| object | Object to be uploaded. | No |
| type | Object type- json | No |
| useCustomSerializer | True or False. Whether to use the custom serializer or not. The default value is true. The custom serializer will be always used for XML deserialization. If false, the XML/JSON deserialization will be done using the default ColdFusion behavior. If any other type is passed with useCustomSerializer as false, then TypeNotSupportedException will be thrown. For more information, see Serialize. | No |
| objectLockLegalHoldStatus | Indicates whether the specified object has a Legal Hold in place.. Valid values are:
|
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create the bucket
rootObj=storageService.bucket("bucket.download.object","true")
key = "key12"
a=["a","b","c","d"];
// define upload struct
uploadStruct = {
"type": "json",
"object" : a,
"key" : key
}
// upload an object
try{
rootObj.uploadObject(uploadStruct)
writeOutput("Object uploaded successfully")
}
catch(any e){
writeOutput("Failed to upload object")
writeDump(e)
}
// define download struct
downloadStruct = {
"type": "json",
"key" : key
}
// download the object
try{
rootObj.downloadObject(downloadStruct)
writeOutput("Object downloaded successfully")
}
catch(any e){
writeOutput("Failed to download object")
writeDump(e)
}
</cfscript>downloadObject(parameterStruct)| Parameter | Description | Required |
| key | Unique identifier of the object. | Yes |
| cacheControl | Set the cache control header of the object, | No |
| contentDisposition | Set the Content-Disposition header of the response. | No |
| contentEncoding | Set the Content-Encoding header of the response. | No |
| contentLanguage | Set the Content-Language header of the response. | No |
| contentType | Set the Content-Type header of the response. | No |
| expires | Sets the Response header of the response. | No |
| versionId | Refer to a specific version of the object. | No |
| sseCustomerAlgorithm | Specify the algorithm to use to when encrypting the object. | No |
| sseCustomerKey | Specify the customer-provided encryption key for S3 to use in encrypting data. | No |
| requestPayer | Confirms that the requester knows that they will be charged for the request. | No |
| type | Object type- json | No |
| useCustomSerializer | True or False | No |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create the bucket
rootObj=storageService.bucket("bucket.download.object","true")
key = "key12"
a=["a","b","c","d"];
// define upload struct
uploadStruct = {
"type": "json",
"object" : a,
"key" : key
}
// upload an object
try{
rootObj.uploadObject(uploadStruct)
writeOutput("Object uploaded successfully")
}
catch(any e){
writeOutput("Failed to upload object")
writeDump(e)
}
// define download struct
downloadStruct = {
"type": "json",
"key" : key
}
// download the object
try{
rootObj.downloadObject(downloadStruct)
writeOutput("Object downloaded successfully")
}
catch(any e){
writeOutput("Failed to download object")
writeDump(e)
}
</cfscript>uploadDirectory(parameterStruct)Parameter | Description | Required |
prefix | It is the prefix that will be added to the object key while uploading. | Yes |
sourceDirectory | The location of the directory to upload. | Yes |
uploadNestedDirectory | True or False. Specify if you want to include sub-directories inside the main folder. | No |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.b.four",
"objectLockEnabledForBucket" : true
}
bucketObj=storageService.createBucket(createBucketRequest)
// define request parameters for upload
dirUploadReq = {
"prefix" : "test_bulk\",
"sourceDirectory" : "../files",
"uploadNestedDirectory" : true
}
try{
uploadResponse=storageService.uploadDirectory(dirUploadReq)
writeOutput("Directory uploaded successfully")
writeDump(uploadResponse)
}
catch(any e){
writeDump(e)
}
</cfscript>putObjectLockConfiguration(parameterStruct)Parameter | Description | Required |
objectLockConfiguration | The root level tag for the ObjectLockConfiguration parameters. | Yes |
objectLockEnabled | Whether this bucket has an Object Lock configuration enabled. Valid values are: ENABLED | No |
defaultRetention | Struct containing the following: mode: The Object locking mode that you want to apply to this object. Valid values are:
days: Number of days to lock the object for. years: Number of years to lock the object for. Note: Specify either days or years, not both. | No |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.demo.getobjectlock",
"objectLockEnabledForBucket" : true
}
// create a bucket
bucketObj=storageService.createBucket(createBucketRequest)
// upload an object to the bucket
uploadStruct={
"srcFile":"#ExpandPath('./')#/s3-notes.pdf",
"key":"key161"
}
bucketObj.uploadFile(uploadStruct)
// put object lock
putObjectLockRequest = {
"objectLockConfiguration" : {
"objectLockEnabled" : "ENABLED",
"defaultRetention" : {
"mode" : "GOVERNANCE",
"days" : 31
}
}
}
bucketObj.putObjectLockConfiguration(putObjectLockRequest)
// get object lock
objectLockResponse=bucketObj.getObjectLockConfiguration()
writeDump(objectLockResponse)
</cfscript>getObjectLockConfiguration()<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.demo.getobjectlock",
"objectLockEnabledForBucket" : true
}
// create a bucket
bucketObj=storageService.createBucket(createBucketRequest)
// upload an object to the bucket
uploadStruct={
"srcFile":"#ExpandPath('./')#/s3-notes.pdf",
"key":"key161"
}
bucketObj.uploadFile(uploadStruct)
// put object lock
putObjectLockRequest = {
"objectLockConfiguration" : {
"objectLockEnabled" : "ENABLED",
"defaultRetention" : {
"mode" : "GOVERNANCE",
"days" : 31
}
}
}
bucketObj.putObjectLockConfiguration(putObjectLockRequest)
// get object lock
objectLockResponse=bucketObj.getObjectLockConfiguration()
writeDump(objectLockResponse)
</cfscript>acquireLegalHold(parameterStruct)Parameter | Description | Required |
key | The key name for the object that you want to place a Legal Hold on. | Yes |
versionId | The version ID of the object that you want to place a Legal Hold on. | No |
legalHold | The root level tag for the LegalHold parameters. Struct containing the following: status: ON or OFF | No |
requestPayer | Confirms that the requester knows that they will be charged for the request. Valid value is: REQUESTER | No |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.demo.acquirelegalhold",
"objectLockEnabledForBucket" : true
}
// create a bucket
bucketObj=storageService.createBucket(createBucketRequest)
// upload an object to the bucket
uploadStruct={
"srcFile":"#ExpandPath('./')#/s3-notes.pdf",
"key":"key121"
}
bucketObj.uploadFile(uploadStruct)
// enable versioning
bucketObj.enableVersioning()
// list all versions
list=bucketObj.listAllVersions()
// get version Id
v_id=list.response[1].versionId
// acquire legal hold request
acquireLegalHoldRequest = {
"key" : "key121",
"versionId" : "#v_id#",
"legalHold" : {
"status" : "ON"
},
"requestPayer" : "REQUESTER"
}
try{
acquireHoldResponse=bucketObj.acquireLegalHold(acquireLegalHoldRequest)
writeDump(acquireHoldResponse)
}
catch (any e){
writeDump(e)
}
</cfscript>getLegalHold(parameterStruct)Parameter | Description | Required |
key | The key name for the object whose Legal Hold status you want to get. | Yes |
versionId | The version ID of the object whose Legal Hold status you want to get. | No |
requestPayer | Confirms that the requester knows that they will be charged for the request. Valid value is: REQUESTER | No |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.demo.getlegalhold",
"objectLockEnabledForBucket" : true
}
// create a bucket
bucketObj=storageService.createBucket(createBucketRequest)
// upload an object to the bucket
uploadStruct={
"srcFile":"#ExpandPath('./')#/s3-notes.pdf",
"key":"key141"
}
bucketObj.uploadFile(uploadStruct)
// enable versioning
bucketObj.enableVersioning()
// list all versions
list=bucketObj.listAllVersions()
// get version Id
v_id=list.response[1].versionId
// get legal hold status on the object
getLegalHoldRequest = {
"key" : "key141",
"versionId" : "#v_id#",
"requestPayer" : "REQUESTER"
}
getLegalHoldResponse=bucketObj.getLegalHold(getLegalHoldRequest)
writeDump(getLegalHoldResponse)
</cfscript>acquireRetentionLock(parameterStruct)Parameter | Description | Required |
key | The key name for the object that you want to apply this Object Retention configuration to. | Yes |
versionID | The version ID for the object that you want to apply this Object Retention configuration to. | No |
retention | Struct containing the following:
| No |
requestPayer | Confirms that the requester knows that he/she will be charged for the request. | No |
bypassGovernanceRetention | Whether this operation must bypass Governance-mode restrictions. |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.demo.acquireretentionlock",
"objectLockEnabledForBucket" : true
}
// create a bucket
bucketObj=storageService.createBucket(createBucketRequest)
// upload an object to the bucket
uploadStruct={
"srcFile":"#ExpandPath('./')#/s3-notes.pdf",
"key":"key131"
}
bucketObj.uploadFile(uploadStruct)
// enable versioning
bucketObj.enableVersioning()
// list all versions
list=bucketObj.listAllVersions()
// get version Id
v_id=list.response[1].versionId
retainDate=DateFormat(DateAdd("d",8,now()),"yyyy-mm-dd")
retentionRequestStruct = {
"key" : "key131",
"versionId" : "#v_id#",
"retention" : {
"mode" : "GOVERNANCE",
"retainUntilDate" : "#retainDate#"
},
"requestPayer" : "REQUESTER",
"bypassGovernanceRetention" : false
}
try{
acquireRetentionLockResponse=bucketObj.acquireRetentionLock(retentionRequestStruct)
writeDump(acquireRetentionLockResponse)
}
catch(any e){
writeDump(e)
}
</cfscript>getRetentionLock(parameterStruct)Parameter | Description | Required |
key | The key name for the object for which you want to retrieve this Object Retention configuration. | Yes |
versionId | The version id for the object for which you want to retrieve this Object Retention configuration. | No |
requestPayer | Confirms that the requester knows that he/she will be charged for the request. Valid value is: REQUESTER | No |
<cfscript>
storageService = getCloudService(application.awsCred, application.s3Conf)
createBucketRequest = {
"bucket" : "bucket.demo.lock",
"objectLockEnabledForBucket" : "true"
}
rootObj=storageService.createBucket(createBucketRequest)
//rootObj=storageService.bucket("cfqa2.test123456",true);
rootObj.enableVersioning()
// upload a file
uploadRequest = {
"srcFile" : "test.txt",
"key" : "test",
"validateContentMD5":"true",
"objectLockMode" : "GOVERNANCE",
"objectLockRetainUntilDate" : "2019-12-11",
"objectLockLegalHoldStatus" : "ON"
}
rootObj.uploadFile(uploadRequest);
//writedump(uploadResponse)
request1 = {
"objectLockConfiguration" : {
"objectLockEnabled" : "ENABLED",
"defaultRetention" : {
"mode" : "GOVERNANCE",
"days" : "2",
"years": "1"
}
}
}
rootObj.putObjectLockConfiguration(request1)
retentionRequest = {
"key" : "test",
"retention" : {
"mode" : "GOVERNANCE",
"retainUntilDate" : "{ts '2019-11-27 12:13:50'}"
},
"bypassGovernanceRetention" :"true"
}
rootObj.acquireRetentionLock(retentionRequest)
getRetentionRequest={
"key" : "test"
}
writedump(rootObj.getRetentionLock(getRetentionRequest))
</cfscript>enableRequesterpay()<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "sg.bucket",
"objectLockEnabledForBucket" : true
}
// create a bucket
myobj=storageService.createBucket(createBucketRequest)
// Enabling "Requester Pays" on bucket:
myobj.enableRequesterpay()
// Get Requester Pay status:
getResponse=myobj.getRequesterPayStatus()
writeDump(getResponse)
</cfscript>disableRequesterPay()<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.demo.disablerequester",
"objectLockEnabledForBucket" : true
}
// create a bucket
bucketObj=storageService.createBucket(createBucketRequest)
// Enabling "Requester Pays" on bucket
bucketObj.enableRequesterpay()
// Disable requester pay status on the bucket
try{
disableRequesterPayResponse=bucketObj.disableRequesterPay()
writeOutput("Requester pay disabled")
writeDump(disableRequesterPayResponse)
}
catch (any e){
writeOutput("Unable to disable requester pay")
writeDUmp(e)
}
</cfscript>getRequesterPayStatus()<cfscript>
storageService = cloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.demo.getrequester",
"objectLockEnabledForBucket" : true
}
// create a bucket
bucketObj=storageService.createBucket(createBucketRequest)
// Enabling "Requester Pays" on bucket
bucketObj.enableRequesterpay()
// Get the requester pay details
getRequesterPayResponse=bucketObj.getRequesterPayStatus()
writeDump(getRequesterPayResponse)
</cfscript>putSecurityAccessBlock(parameterStruct)Parameter | Description | Required |
blockPublicAcls | TRUE or FALSE. Whether S3 must block public access control lists (ACLs) for this bucket and objects in this bucket. | No |
ignorePublicAcls | TRUE or FALSE. Whether S3 must ignore public access control lists (ACLs) for this bucket and objects in this bucket. | No |
blockPublicPolicy | TRUE or FALSE. Whether S3 must block public bucket policies for this bucket. | No |
restrictPublicBuckets | TRUE or FALSE. Whether S3 must restrict public bucket policies for this bucket. | No |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.demo.getpublicaccess",
"objectLockEnabledForBucket" : true
}
bucketobj=storageService.createBucket(createBucketRequest)
pubAccessReq = {
"publicAccessBlockConfiguration" : {
"blockPublicAcls" : true,
"ignorePublicAcls" : true,
"blockPublicPolicy" : true,
"restrictPublicBuckets" : true
}
}
try{
accessBlockResponse=bucketobj.putSecurityAccessBlock(pubAccessReq)
writeOutput("Block to public access enforced successfully")
writeDump(accessBlockResponse)
}
catch(any e){
writeOutput("Failed to block public access")
writeDump(e)
}
// get the block details
getBlockResponse=bucketobj.getSecurityAccessBlock()
writeDump(getBlockResponse)
</cfscript>getSecurityAccessBlock()<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.demo.getpublicaccess",
"objectLockEnabledForBucket" : true
}
bucketobj=storageService.createBucket(createBucketRequest)
pubAccessReq = {
"publicAccessBlockConfiguration" : {
"blockPublicAcls" : true,
"ignorePublicAcls" : true,
"blockPublicPolicy" : true,
"restrictPublicBuckets" : true
}
}
try{
accessBlockResponse=bucketobj.putSecurityAccessBlock(pubAccessReq)
writeOutput("Block to public access enforced successfully")
writeDump(accessBlockResponse)
}
catch(any e){
writeOutput("Failed to block public access")
writeDump(e)
}
// get the block details
getBlockResponse=bucketobj.getSecurityAccessBlock()
writeDump(getBlockResponse)
</cfscript>getLocation()<cfscript>
storageService = getCloudService(application.awsCred, application.s3Conf)
// create a bucket
createBucketRequest = {
"acl":"PRIVATE",
"bucket" : "bucket.demo.loc",
"objectLockEnabledForBucket" : true
}
// create a bucket
bucketObj=storageService.createBucket(createBucketRequest)
// get bucket location
bucketLoc=bucketObj.getLocation()
writeDump(bucketLoc)
</cfscript>getObjectMetadata(parameterStruct)Parameter | Description | Required |
key | The key with which the object was uploaded. | Yes |
versionId | The version id associated with the object. | No |
<cfscript>
storageService = cloudService(application.awsCred,application.s3Conf)
// create a bucket
bucketStruct={
"acl":"PRIVATE",
"bucket" : "bucket.demo.objectmetadatademo",
"objectLockEnabledForBucket" : true
}
bucketObj=storageService.createBucket(bucketStruct)
// upload an object into the bucket
uploadStruct={
"srcFile" : "#ExpandPath('./')#/Colors.jpg",
"key" : "key001",
"metadata": {
"filename": "Colors.jpg",
"creator":"john",
"place":"london",
"creation_date":"2020/04/20",
"filetype":"image"
}
}
bucketObj.uploadFile(uploadStruct)
// get object metadata
objectMetadataResponse=bucketObj.getObjectMetadata("key001")
writeDump(objectMetadataResponse)
</cfscript>generateGetPresignedUrl(parameterStruct)| Parameter | Description | Required |
| duration | Duration of the url in days. | No |
| key | The key associated with the object. | Yes |
| cacheControl | Specify the caching behavior as defined here. | No |
| contentDisposition | Specify the content format of the object as defined here. | No |
| contentEncoding | Specify the type of encoding on the object as defined here. | No |
| contentLanguage | The language of the object that you want to upload. | No |
| contentType | The format of the content as defined here. | No |
| expires | The date and time when the object cannot be cached any longer. | No |
| versionId | The version id of the object. | No |
| sseCustomerAlgorithm | Specifies the algorithm to use to when encrypting the object. | No |
| sseCustomerKey | Specifies the customer-provided encryption key for S3 to use in encrypting data. | No |
| sseCustomerKeyMD5 | Specifies the MD5 of the key. | No |
| requestPayer | Confirms that the requester knows that they will be charged for the request. | No |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"bucket" : "bucket.parallel.getpresignedurl"
}
rootObj = storageService.createBucket(createBucketRequest)
// upload a file
src = "#ExpandPath('..')#/files/file.txt"
key = "key12"
uploadStruct = {
"srcFile" : src,
"key" : key
}
rootObj.uploadFile(uploadStruct)
// Pre signed url struct
getPresignedUrlRequest = {
"duration": "1d", // 1 day
"key":key
}
getPresignedUrlResp = rootObj.generateGetPresignedUrl(getPresignedUrlRequest)
writeDump(getPresignedUrlResp)
</cfscript>generatePutPresignedUrl(parameterStruct)Parameter | Description | Required |
duration | Duration of the url in days. | No |
key | The key associated with the object. | Yes |
<cfscript>
storageService = getCloudService(application.awsCred,application.s3Conf)
// create a bucket
createBucketRequest = {
"bucket" : "bucket.parallel.putpresignedurl"
}
rootObj = storageService.createBucket(createBucketRequest)
putPresignedReq = {
"duration": "1d", // 1 day
"key" : "key12"
}
putPresignedUrlResp = rootObj.generatePutPresignedUrl(putPresignedReq);
writedump(putPresignedUrlResp)
</cfscript>