简体   繁体   中英

java gae google cloud storage iterate over files in bucket

I have the following file structure in my publicly accessible bucket:

somedirs/somefiles.html

The html files show up in my bucket and I can access them in the browser and read/write from/to them in my application. I now want to iterate over all files (on gae with latest java sdk) to generate my sitemap.xml.

I was going for the following approach:

ListResult fileList = GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance())
    .list("mybucket", new ListOptions.Builder().setRecursive(true).build());
String dir = null;
while (fileList.hasNext()) {
    ListItem file = fileList.next();
    if (file.isDirectory()) {
        dir = file.getName();
        continue;
    } else if(dir == null)
        continue;
    //generate XML form file meta-data, name and dir name
}

My problem is that the file list seems to be empty hence my sitemap.xml is empty as well. The documentation and API documentation lack information on how to do it right.

Any suggestions?

It turns out that file.isDirectory() never returns true. Instead file.getName() returns somedir/somefile.html .

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