• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

ColdFusion 2023 S3 delete object example

New Here ,
Aug 03, 2023 Aug 03, 2023

Copy link to clipboard

Copied

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.

Views

8.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Engaged , Aug 10, 2023 Aug 10, 2023

I've just found bug tracker CF-4218035 which claims this issue is fixed, but will be released in HF5?  We're up to date with our CF updates  (2023 update 3!), so this doesn't help us to know when this fix will be released.

Votes

Translate

Translate
Engaged , Aug 10, 2023 Aug 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-4a8d063251f05

...

Votes

Translate

Translate
Community Expert ,
Aug 03, 2023 Aug 03, 2023

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 04, 2023 Aug 04, 2023

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 04, 2023 Aug 04, 2023

Copy link to clipboard

Copied

I'm running into the exact same problem myself. In my case, I am using <cffile action="readBinary"> with all of the credentials inline (in plaintext as well, for testing).

 

  • I was running CF 2018 locally for development and it worked fine, but when I uploaded to the production server (CF 2021) it broke.
  • I had read that in CF 2021+, AWS functionality was an add-on (which my hosting provider assured was installed already). To test, I migrated my development server locally to CF 2023 (and checked to ensure all packages, including AWS, were installed), and immediately my code broke.
  • Therefore, I feel something must have changed from CF 2018 to CF 2021/2023 as nothing has changed with my code--which again is in plaintext and has not been edited from when it was originally working on CF 2018 exactly one week ago.

 

If I can find any updates or fixes, I'll be sure to post them here to help! I love all of the new things that CF can do with AWS but I really just need simple file operations to work as this is an important part of my application.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 05, 2023 Aug 05, 2023

Copy link to clipboard

Copied

While you each struggle with (and await any resolution to) problems using the former s3 operations in cf2021 and above, can you each consider just using the newer s3 capabilities that WERE added in cf2021?

 

I realize you want want DID work to STILL work, You're not wrong that it should-- and I've not heard that what you're experiencing has been a common problem since cf2021 came out nearly 3 years ago (Nov 2020).

 

And FWIW, I'd not offered this in my first reply as I wanted to start with the simpler possibility. 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 05, 2023 Aug 05, 2023

Copy link to clipboard

Copied

I'll add that I have found that just this week someone HAS raised this issue on tracker, and others have already chimed in to concur.

https://tracker.adobe.com/#/view/CF-4218919

 

It's odd, though, as again a search for s3 there (leaving off any cf version) found only that and not others which seemed to be about simply using that old functionality on cf2021 and above.

 

So get your votes in there, you and others who find this discussion. 🙂 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 09, 2023 Aug 09, 2023

Copy link to clipboard

Copied

Please help. We are trying to migrate off CF2018 to CF2023 but we must have access to delete files in AWS S3. We are willing to change our code to work with whatever Adobe requires for CF2023, we just need a sample code that will work with the existing CF2023 architecture to delete an object in S3. Currently Adobe only provides an example of how to delete an entire bucket in S3. That is not acceptable. We only need to delete an object. We are running CF2023 Enterprise, Update 3.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 07, 2023 Aug 07, 2023

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 09, 2023 Aug 09, 2023

Copy link to clipboard

Copied

I cannot. And I see that the docs don't show any capability to do it. 

 

(To be clear, when I propoesd on Aug 5 to consider the new CF2021 features, I was not saying that I knew it COULD do the delete of an object. I was just putting forth the option to look into. Again, either of you may have replied that you were NOT interested in changing your code. That's why I next offered the tracker ticket about the issue of using the previous code on CF2021 and above.)

 

So now as for this inability for the new capability to allow delete of an object, I will say first that I don't see anyone having raised the concern in tracker--so again, that would be a first thing to pursue.

 

Second, you could email cfsup@adobe.com. They may reply with some undocumented solution.

 

Third, as you may know there is a blog post from Adobe that introduced the new s3 feature set when CF2021 came out. In fact, I added a comment there asking about it, but since it's from nearly 3 years ago, the writer of the post (who I assume is an Adobe employee) may not see the comment, may not get notified about it, and may not even still be at Adobe.

 

Sorry I can't offer more. I appreciate the desparation you are feeling. Maybe someone else will offer an idea.

 

If not, here's one last hail mary: you could consider keeping CF2018 installed to use even if ONLY to make such s3 calls. You could call into that from CF2021 using cfhttp.


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 10, 2023 Aug 10, 2023

Copy link to clipboard

Copied

We have just run into the same issue after upgrading from 2018 to 2023, and I've put my vote into the bug tracker.  All previous S3 capabilities that we using with CF2018 file and directory functions no longer work.  FileExists(), directoryExists(), etc....

 

Can't wait for Adobe to fix.  Will be looking into 2023's new S3 functions.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 10, 2023 Aug 10, 2023

Copy link to clipboard

Copied

I've just found bug tracker CF-4218035 which claims this issue is fixed, but will be released in HF5?  We're up to date with our CF updates  (2023 update 3!), so this doesn't help us to know when this fix will be released.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 10, 2023 Aug 10, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 10, 2023 Aug 10, 2023

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 22, 2024 Feb 22, 2024

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation