Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 670
  • Last Modified:

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
0
spencerian
Asked:
spencerian
  • 9
  • 9
1 Solution
 
Gurpreet Singh RandhawaWeb DeveloperCommented:
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
 
spencerianAuthor Commented:
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
 
dgrafxCommented:
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
Simple Misconfiguration =Network Vulnerability

In this technical webinar, AlgoSec will present several examples of common misconfigurations; including a basic device change, business application connectivity changes, and data center migrations. Learn best practices to protect your business from attack.

 
spencerianAuthor Commented:
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
 
dgrafxCommented:
let me ask - are you able to put files on S3?
0
 
spencerianAuthor Commented:
yes, but not with Coldfusion if that is what you are asking.
0
 
dgrafxCommented:
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
 
spencerianAuthor Commented:
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
 
dgrafxCommented:
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
 
spencerianAuthor Commented:
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
 
dgrafxCommented:
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
 
spencerianAuthor Commented:
Have read and tried and Like many others I cannot get it to work.
0
 
dgrafxCommented:
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
 
spencerianAuthor Commented:
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
 
dgrafxCommented:
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
 
spencerianAuthor Commented:
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
 
dgrafxCommented:
@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
 
spencerianAuthor Commented:
I actually ended up hiring a developer to write the code:)

Who said anything about EE not being a good deal?????
0
 
dgrafxCommented:
Right on  !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Building an Effective Phishing Protection Program

Join Director of Product Management Todd OBoyle on April 26th as he covers the key elements of a phishing protection program. Whether you’re an old hat at phishing education or considering starting a program -- we'll discuss critical components that should be in any program.

  • 9
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now