How to check if file/key exists?

Oct 27, 2008 at 7:50 AM
Can anyone help me out with this?  I want to be able to use ThreeSharp (or any other method) to check whether a key name already exists in my S3 bucket?  This is probably quite simple, but I'm a bit lost with what to do. 

Thanks in advance, Steve
Nov 20, 2008 at 6:51 PM
You could generate a URL (a signed URL if the content is not available anonymously) and then do a HTTP head on that URL. If statuscode is 404 then the file does not exist.

I've found the latency to be pretty poor with this method however.
Nov 21, 2008 at 7:05 PM
What I did was to extend the code as follows:

    public class ObjectHeadRequest : Request
        public ObjectHeadRequest(String bucketName, String key)
            this.Method = "HEAD";
            this.BucketName = bucketName;
            this.Key = key;

    public class ObjectHeadResponse : Response


        public ObjectHeadResponse ObjectHead (ObjectHeadRequest request)
            return Invoke<ObjectHeadResponse>(request);

ThreeSharp.cs in the IThreeSharp interface
        /// <summary>
        /// Gets an objects header info without streaming it
        /// </summary>
        ObjectHeadResponse ObjectHead (ObjectHeadRequest request);

It would be good if this capability could be added to the library.

Nov 30, 2008 at 8:02 PM
I second that. This should be added to the next release.
Feb 24, 2009 at 11:00 PM
I agree and added this as an issue to vote on: