简体   繁体   中英

Read the file count in a public AWS S3 bucket

I am able to retrieve the XML which contains the info about the files using the below piece of code:

XElement responseXML = XElement.Load(AWS_S3_URL);        
ICollection<XElement> fileElements = responseXML.Elements("Contents") as ICollection<XElement>;
Debug.Log("responseXML.Elements() ===== " + fileElements.ToString());

The first line of code returns the following xml. But I am not able to retrieve the count of element:

<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <Name>XXXXXXXXXXXX</Name>
    <Prefix />
    <Marker />
    <MaxKeys>1000</MaxKeys>
    <IsTruncated>false</IsTruncated>
    <Contents>
        <Key>AffectivaLogs/</Key>
        <LastModified>2018-04-16T00:20:06.000Z</LastModified>
        <ETag>"d41d8cd98f00b204e9800998ecf8427e"</ETag>
        <Size>0</Size>
        <Owner>
            <ID>65a011a29cdf8ec533ec3d1ccaae921c</ID>
        </Owner>
        <StorageClass>STANDARD</StorageClass>
    </Contents>
    <Contents>
        <Key>Bean Man with Affectiva.Editor.csproj</Key>
        <LastModified>2018-04-16T05:40:43.000Z</LastModified>
        <ETag>"7ea67a5fa37ceaeaa90ef3dbebddb201"</ETag>
        <Size>34349</Size>
        <StorageClass>STANDARD</StorageClass>
    </Contents>
</ListBucketResult>

Able to do it easily using XmlDocument instead of XElement .

XmlDocument responseXML = new XmlDocument();
responseXML.Load(AWS_S3_URL);
XmlElement root = responseXML.DocumentElement;
XmlNodeList node = root.GetElementsByTagName("Contents");        
Debug.Log("responseXML.Elements() ===== " + node.Count);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM