Your code really works for me, but there are a few things you need to know.
As I understand it, Amazon S3 does not have the concept of folders, but individual clients can display S3 objects as if they were doing it. Therefore, if you create an object named A / B, then the client can display it as if it were object B inside a folder named A. This is intuitive and seems to have become standard, but simulating an empty folder does not appear to have a standard.
For example, I used your method to create a folder called Test, and then actually created an object called Test /. But I created the Test2 folder in AWS Explorer (that is, an addon to Visual Studio), and in the end she created an object called Test2 / Test2_ $ folder $ (AWS Explorer will display both Test and Test2 as folders)
Once out of what this means is that you do not need to create a โfolderโ before you can use it, which may mean that you do not need the DoFolderExist method.
As I mentioned, I tried my code and it works and finds the created Test folder, but the key had to be changed to find the folder created by AWS Explorer, i.e.
DoesFolderExist("Test/" , bucketName); // Returns true DoesFolderExist("Test2/" , bucketName); // Returns false DoesFolderExist("Test2/Test2_$folder$", bucketName); // Returns true
So, if you still want to have a DoFolderExist method, then it might be safer to just look for any objects that start with folderName + "/", that is, something like
ListObjectsRequest request = new ListObjectsRequest(); request.BucketName = bucketName ; request.WithPrefix(folderName + "/"); request.MaxKeys = 1; using (ListObjectsResponse response = m_S3Client.ListObjects(request)) { return (response.S3Objects.Count > 0); }
sgmoore
source share