Skip to main content
TallyCF
Participating Frequently
August 3, 2023
Answered

ColdFusion 2023 S3 delete object example

  • August 3, 2023
  • 2 replies
  • 10681 views

We are migrating from CF2018 to CF2023 and many of our S3 calls have broken. In CF2018 we are using delete object calls like this:

 

fileDelete("s3://#s3accessKeyId#:#s3awsSecretKey#@#s3Bucket#/#object#")

 

When we try the same code on CF2023 we get this error:

Cannot invoke "java.lang.Boolean.booleanValue()" because the return value of "coldfusion.vfs.s3.S3FileSystemConfigBuilder.getParam(org.apache.commons.vfs2.FileSystemOptions, String)" is null null

 

Any help figuring out how to delete a file in S3 would be greatly appreciated.

    This topic has been closed for replies.
    Correct answer sdsinc_pmascari

    Hello Charlie,

     

    I would be happy to use new code to make the delete object work. I cannot find any examples of how to do this in CF2021 or CF2023 documentation. Can you provide an example of how to delete a S3 object (not a bucket) that will work in CF2023?


    I have discovered how to delete an object on S3 using the new CF2023 cloud functions.

    First, I've entered our AWS S3 creds and config into the CFAdmin and use that to init the object:

    <cfset s3Obj = getCloudService("s3Creds", "cfS3" )>

    Then, create an object specific to the bucket where your object resides:

    <cfset s3Bucket = s3Obj.bucket("myBucketName",false)>

    Create a struct with the full key name in your bucket:

    <cfset delObj = {
        key = "userimages/sample/aPathName/7f4b404c-a15c-7e2f-4a8d063251f055d6.png"
    }>

    You then call an (undocumented) delete function of the bucket object:

    <cfset s3Bucket.delete(delObj)>

     

    Hope this helps

    2 replies

    johnb77214017
    Inspiring
    February 22, 2024

    @TallyCF  Did you ever get fileDelete("s3://#s3accessKeyId#:#s3awsSecretKey#@#s3Bucket#/#object#") working in CF23?

    Charlie Arehart
    Community Expert
    Community Expert
    August 4, 2023

    You may be presuming there has been some change in how cf would perform that operation, but the real problem may be that something has caused all those variables to differ in value (between how your app runs in cf2018 and 2023).

     

    Since you have both available to you ("are migrating"), do this as a sanity check: wrap a cfoutput/writeOutput around those vars:

     

    #s3accessKeyId#:#s3awsSecretKey#@#s3Bucket#/#object#

     

    Do the results differ at all (for the same request) on the two instances? 

    /Charlie (troubleshooter, carehart. org)
    TallyCF
    TallyCFAuthor
    Participating Frequently
    August 4, 2023

    I've done as suggested and output all the variables in CF2018 and CF2023. The strings are identical in both version. The code works in CF2018 but does not work in CF2023. CF documentation on how to access AWS S3 is very limited. In fact there is no example of how to delete an object at all. (There is an example of how to delete an entire bucket, but that is not what I am trying to do.) I just need to delete an object.

     

    Can anyone provide some sample code to simply delete an object in S3 using CF2023? The fileDelete() method does not seem to work in CF2023 sp3.

    sdsinc_pmascariCorrect answer
    Legend
    August 10, 2023

    Hello Charlie,

     

    I would be happy to use new code to make the delete object work. I cannot find any examples of how to do this in CF2021 or CF2023 documentation. Can you provide an example of how to delete a S3 object (not a bucket) that will work in CF2023?


    I have discovered how to delete an object on S3 using the new CF2023 cloud functions.

    First, I've entered our AWS S3 creds and config into the CFAdmin and use that to init the object:

    <cfset s3Obj = getCloudService("s3Creds", "cfS3" )>

    Then, create an object specific to the bucket where your object resides:

    <cfset s3Bucket = s3Obj.bucket("myBucketName",false)>

    Create a struct with the full key name in your bucket:

    <cfset delObj = {
        key = "userimages/sample/aPathName/7f4b404c-a15c-7e2f-4a8d063251f055d6.png"
    }>

    You then call an (undocumented) delete function of the bucket object:

    <cfset s3Bucket.delete(delObj)>

     

    Hope this helps