I am using below snippets of code to get the list of files from Azure Blob container:
public static String[] listFolder( String containerURI, String sasToken, String dirPrefix) throws StorageException, URISyntaxException{
ArrayList<String> files = new ArrayList<String>();
// Get a reference to a container
CloudBlobContainer container = (new CloudBlockBlob(new URI(containerURI + "?" + sasToken))).getContainer();
CloudBlobDirectory directory = container.getDirectoryReference(dirPrefix);
if (directory.listBlobs() != null) {
for (ListBlobItem item : directory.listBlobs()) {
CloudBlockBlob blob = (CloudBlockBlob)item;
files.add(blob.getName());
}
}
return files.toArray(new String[files.size()]);
}
But I am getting an exception
While executing [invoke] encountered [java.util.NoSuchElementException] : [An error occurred while enumerating the result, check the original exception for details. at
com.microsoft.azure.storage.core.LazySegmentedIterator.hasNext(LazySegmentedIterator.java:113)]
Does anyone have any pointer to what is wrong with the code, or does it need any modification?