public IFile GetFile(string path) { GetObjectMetadataRequest request = new GetObjectMetadataRequest { BucketName = _bucketName, Key = path }; GetObjectMetadataResponse response = _client.GetObjectMetadata(request); IFile file = new AmazonS3File(); file.Path = path; file.Size = response.ContentLength; file.LastModified = response.LastModified; return(file); }
public IEnumerable <IFile> GetFiles(string path) { var prefix = path.Length > 1 ? path : string.Empty; ListObjectsRequest request = new ListObjectsRequest { BucketName = _bucketName, Prefix = prefix, Delimiter = PathDelimiter.ToString() }; ListObjectsResponse response = _client.ListObjects(request); List <IFile> files = new List <IFile>(); // add directories foreach (string directory in response.CommonPrefixes) { IFile file = new AmazonS3File(); file.Path = directory; file.IsDirectory = true; files.Add(file); } // add files foreach (S3Object entry in response.S3Objects) { IFile fileDescription = new AmazonS3File() { Path = entry.Key, IsDirectory = false, LastModified = entry.LastModified, Size = entry.Size }; files.Add(fileDescription); } return(files); }