Link to home
Start Free TrialLog in
Avatar of spencerian
spencerian

asked on

How to use CFFILE to read/delete S3 objects

I have searched and cant find a solution..
Basically want to interact with a S3 bucket using CFFILE.
So how would something like this look"

<cfset imgfile = 'PATH TO MY S3 BUCKET' /IMG.jpg'>
<cfif  FileExists(imgfile) EQ 'YES'>
<cffile  action="delete" file="#imgfile#"> 

Open in new window


Thanks
Avatar of Coast Line
Coast Line
Flag of Canada image

First of all try to check your image Path

<cfset imgfile = 'PATH TO MY S3 BUCKET' /IMG.jpg'>
<cfif  FileExists(imgfile)>
<cffile  action="delete" file="#imgfile#"> 

Open in new window


<cfdump var="#imgfile#"> 

Open in new window

- Check what is the path of the file and does the file is in correct location, if yes, first try to see if file is visible on screen and if yes then delete it
Avatar of spencerian
spencerian

ASKER

You see as far as I can tell from reading documentation:
S3 access is not available using CFFILE and CFDIRECTORY
So I am looking for the correct method.
You are correct when you say that S3 is not available to cffile & cfdirectory.
Here is a link to the documentation: http://docs.aws.amazon.com/AmazonS3/latest/dev/DeletingObjects.html 

Here is a link with some relevant details: http://stackoverflow.com/questions/27226803/amazon-s3-coldfusions-fileexists-breaks-when-file-was-deleted-by-s3cmd
I have read thru this and still having trouble understanding how i pass my KeyID and Secretkey to AWS.
Can you provide an example?
let me ask - are you able to put files on S3?
yes, but not with Coldfusion if that is what you are asking.
yes that's what I'm asking ...
is there a reason why you are adding files with something other than CF but wanting to delete with CF?
and why not delete with whatever you are adding files with?
the key and secret key etc are needed to add files - so why not the same method?
Ok..
I have a bucket with about 250,000 images.

The images are put by a third party.

For 'Housekeeping' purposes I need to run a file daily which deletes all "expired" images.

I am using this format:
s3://accessKeyId:awsSecretKey@bucketname/file.jpg

but i get -

The cause of this exception was: org.apache.commons.vfs2.FileSystemException: Unknown message with code "S3 Error Message."..
http://www.petefreitag.com/item/833.cfm

I'm not in a place where I can paste actual code for you right now but start with that
I had a good look at that,
I could not get it to  work for me.
Actually i have no need to put files, only read and delete...
I am back home again and thought I'd post a couple things.

http://www.raymondcamden.com/2010/07/15/CF901-Guide-to-Amazon-S3-support-in-ColdFusion-901

https://forums.aws.amazon.com/message.jspa?messageID=40663

I post the following because I ran across an article on coldfusionjedi.com while researching this and the article was complete crap!
A warning to all true believers - that domain is not owned by Ray Camden any longer!
http://www.raymondcamden.com/2014/10/06/ColdFusion-Jedi-is-no-more
Have read and tried and Like many others I cannot get it to work.
I should say that you aren't going to be able to simply send in a url and delete files.
You need to authenticate - otherwise anyone could delete your files. It's required that you send in your policy and signature and etc - and it needs to be hashed.
I posted you different articles that explain how to do this - the encryption as well.
This is why I asked how you were putting files to s3 - because it's similar.
You could login to your amazon s3 account and delete files manually as a secondary option.
Partial Success!
Was able to get this to work
http://amazons3.riaforge.org/
with this fix
http://amazons3.riaforge.org/index.cfm?event=page.issue&issueid=B645A0C9-BF8A-57EF-C50C7D59FE669842

But I still cant figure out how to interact with the Bucket Objects.
I can create a Bucket, upload an object.

But I want  to list and delete Objects based on the file name.
My understanding is that they are a name/key value pair...so how do I query the bucket to get this?
Still searching...
ASKER CERTIFIED SOLUTION
Avatar of dgrafx
dgrafx
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Had to do a lot of research on my own, I guess I pay EE to save time.
Didn't really do that for me. However was guided along the right path,
@spencerian
I'm glad you got it figured out.

However I'd like comment on your comment about paying EE to save time.
Have you ever researched what hiring a developer would cost - say for a couple hours - to help you with your issue?
And then have you compared that to what you pay EE?
Sometimes you get a full answer that tells you exactly what you need and sometimes you just get clues or ideas about your work.
How do you think the economics of having someone work on your problem for a couple hours would play out?
It would be at least as much and probably more than what I mentioned earlier about hiring a developer for a couple hours.
You are in fact getting a good deal paying such a low rate for membership.
If you are new to EE you'll see that in general you can quickly get the answers you are looking for.

good luck ...
I actually ended up hiring a developer to write the code:)

Who said anything about EE not being a good deal?????
Right on  !