use of com.amplifyframework.storage.StorageItem in project amplify-android by aws-amplify.
the class AWSS3StorageListAccessLevelTest method assertListContainsUploadedFile.
private void assertListContainsUploadedFile(StorageListResult result) {
List<StorageItem> items = result.getItems();
assertNotNull(items);
assertEquals(1, items.size());
// Get the first item (there should only be one)
StorageItem storedItem = items.get(0);
assertEquals(UPLOAD_SIZE, storedItem.getSize());
assertEquals(uploadKey, storedItem.getKey());
}
use of com.amplifyframework.storage.StorageItem in project amplify-android by aws-amplify.
the class AWSS3StorageService method listFiles.
/**
* List items inside an S3 path.
* @param path The path to list items from
* @param prefix path appended to S3 keys
* @return A list of parsed items
*/
@NonNull
public List<StorageItem> listFiles(@NonNull String path, @NonNull String prefix) {
startServiceIfNotAlreadyStarted();
ArrayList<StorageItem> itemList = new ArrayList<>();
ListObjectsV2Request request = new ListObjectsV2Request().withBucketName(this.bucket).withPrefix(path);
ListObjectsV2Result result;
do {
result = client.listObjectsV2(request);
for (S3ObjectSummary objectSummary : result.getObjectSummaries()) {
// Remove the access level prefix from service key
String serviceKey = objectSummary.getKey();
String amplifyKey = S3Keys.extractAmplifyKey(serviceKey, prefix);
itemList.add(new StorageItem(amplifyKey, objectSummary.getSize(), objectSummary.getLastModified(), objectSummary.getETag(), null));
}
// If there are more than maxKeys keys in the bucket, get a continuation token
// and fetch the next batch of objects.
String token = result.getNextContinuationToken();
request.setContinuationToken(token);
} while (result.isTruncated());
return itemList;
}
use of com.amplifyframework.storage.StorageItem in project amplify-android by aws-amplify.
the class StorageComponentTest method testListObject.
/**
* Test that calling list method from Storage category correctly
* invokes the registered AWSS3StoragePlugin instance and returns a
* {@link StorageListResult} with list of stored items.
*
* @throws StorageException when an error is encountered while listing
* files inside storage
*/
@Test
public void testListObject() throws StorageException {
final String path = RandomString.string();
final StorageItem item = new StorageItem(RandomString.string(), 0L, new Date(), RandomString.string(), null);
when(storageService.listFiles(anyString(), anyString())).thenReturn(Collections.singletonList(item));
StorageListResult result = Await.<StorageListResult, StorageException>result((onResult, onError) -> storage.list(path, onResult, onError));
assertEquals(item, result.getItems().get(0));
}
Aggregations