2010-07-23 58 views

回答

-1

是的。

您可以使用ListObjectsRequest。使用标记属性,并只检索1个元素。

1

没有ListObjectRequest,而是一个ListObjectsRequest,您无法指定Key。然后,你必须通过所有的对象来找到你想要的。我目前正在寻找它,因为我似乎在下载文件时出错。 (如果有人有一些想法如何解决,可随时发表评论)。

如果您碰巧知道上传ID,则可以尝试使用列表部件请求。

除此之外,我不知道。想与S3 api写个人聊天...

+0

这是一个错字。我更新了我的答案,以更详细地说明如何实现它。 – 2016-02-18 21:10:02

5

你可以使用S3FileInfo类和这个类的Exists方法它会帮助你检查文件是否存在,而不下载文件。例如下面的例子我使用了AWSSDK 3.1.6 .net(3.5):

public static bool ExistsFile() 
{ 
    BasicAWSCredentials basicCredentials = new BasicAWSCredentials("my access key", "my secretkey"); 
       AmazonS3Config configurationClient = new AmazonS3Config(); 
       configurationClient.RegionEndpoint = RegionEndpoint.EUCentral1; 

       try 
       { 
        using (AmazonS3Client clientConnection = new AmazonS3Client(basicCredentials, configurationClient)) 
        { 

         S3FileInfo file = new S3FileInfo(clientConnection, "mybucket", "FolderNameUniTest680/FileNameUnitTest680"); 
         return file.Exists;//if the file exists return true, in other case false 
        } 
       } 
       catch(Exception ex) 
       { 
        return false; 
       } 
    } 
2

试试这个解决方案,它适用于我。

AmazonS3Client client = new AmazonS3Client(accessKey, secretKey, regionEndpoint);  
S3FileInfo s3FileInfo = new S3FileInfo(client, bucketName, fileName); 
if (s3FileInfo.Exists) 
    return true; 
else 
    return false; 
0

你可能不得不使用REST API自己,作为方法的建议,只是内部不完全一样的东西(的try ... catch关于请求)

相关问题