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

ColdFusion 2023 S3 delete object example

  • August 3, 2023
  • 2 replies
  • 10663 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.

    Charlie Arehart
    Community Expert
    Community Expert
    August 10, 2023

    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


    Wonderful, Paul (sdsinc_pmascari). Thanks so much for sharing that. I have gone ahead and marked your last two replies as "the answer". If somehow TallyCF (the op) feels otherwise, they can revert that, of course.

     

    First, about that tracker ticket you named and its reference to an "hf5", I'll offer a guess that an update 4 ("hf4") may be some next security update (perhaps related to the spate of them last month), and then an update 5 will come offering bug fixes also (yay). That's JUST a guess. (Indeed, Adobe usually doesn't name updates but build numbers in that "fixed in" field of tracker...though often it's a build that's in an update not yet released, so that's barely any more clear to us who are on the outside looking in.)

     

    Second, on the solution for the delete, again thanks for digging in. I'll note that I really had a suspicion that may be it (the delete method). While the doc page didn't suggest it was an option, it did show it accepted arguments which I wondered might accept more than just a bucket name.

     

    I didn't mention it in my reply yesterday because unfortunately, when I tried to create a bucket to test things (I don't use s3 normally), I was having trouble getting the access key args to be accepted (AWS was rejecting them) on the call to the bucket method. And since I never had used S3, I just couldn't guess that it might be that sort of object name. Sweet.

     

    So again, on everyone's behalf, thanks so much for trying it and sharing it. Now we just need Adobe to simply document it. I'll add a pointer to this answer in the question I asked on the Adobe blog post I'd mentioned yesterday.

    /Charlie (troubleshooter, carehart. org)