Solved

How to use CFFILE to read/delete S3 objects

Posted on 2015-01-16
19
292 Views
Last Modified: 2015-01-22
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
0
Comment
Question by:spencerian
  • 9
  • 9
19 Comments
 
LVL 15

Expert Comment

by:Gurpreet Singh Randhawa
ID: 40554926
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
0
 

Author Comment

by:spencerian
ID: 40555256
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.
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 40555409
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
0
 

Author Comment

by:spencerian
ID: 40555507
I have read thru this and still having trouble understanding how i pass my KeyID and Secretkey to AWS.
Can you provide an example?
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 40555525
let me ask - are you able to put files on S3?
0
 

Author Comment

by:spencerian
ID: 40555530
yes, but not with Coldfusion if that is what you are asking.
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 40555534
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?
0
 

Author Comment

by:spencerian
ID: 40555548
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."..
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 40555659
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
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:spencerian
ID: 40555717
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...
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 40555862
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
0
 

Author Comment

by:spencerian
ID: 40556420
Have read and tried and Like many others I cannot get it to work.
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 40556441
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.
0
 

Author Comment

by:spencerian
ID: 40556483
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...
0
 
LVL 25

Accepted Solution

by:
dgrafx earned 500 total points
ID: 40556508
ok so now go back to https://forums.aws.amazon.com/message.jspa?messageID=40663 and find the delete code.
should work for you.
0
 

Author Closing Comment

by:spencerian
ID: 40564789
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,
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 40565031
@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 ...
0
 

Author Comment

by:spencerian
ID: 40565051
I actually ended up hiring a developer to write the code:)

Who said anything about EE not being a good deal?????
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 40565055
Right on  !
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
I recently went through setting up a JasperReports Server using the AWS EC2 instance, and this article will cover some basic administration tasks I had to perform.
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now