amplify-js: Storage.list doesn't list contents. Though config correctly displays bucket-name.

Describe the bug Storage.list does not list bucket contents. I’ve tried tons of permutations of paths, but nothing lists.

To Reproduce

    Storage.list('images/photos')
      .then(result => console.log(result))
      .catch(err => console.log(err));


    console.log(Storage);

Expected behavior A list of keys/objects from my bucket.

Screenshots

  1. Example code
  2. Output of code.

storage_snip storage_snip2

Desktop (please complete the following information): Chrome/FF/FF Quantum

I am trying to list the contents in one of my buckets, but nothing seems to be working. Every object is marked as public and there are no ACLs on it. I’ve attached images of my bucket structure below. My guess is I’m somehow messing up the paths.

struct1 struct2

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 23 (4 by maintainers)

Most upvoted comments

Has there been an update on this? I am experience the same issue where my code is returning an empty array when doing the following:

componentWillMount(){
        console.log('Calling S3');
      	Storage.list('/', { level: "public" })
      		.then (result => console.log('Result:', result)) // {key: "test.txt"}
    		.catch(err => console.log(err));
}

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Any progress on this problem? I updated to the latest Amplify libraries for a JavaScript project, and now I am unable to list the contents of a bucket. There is NO OTHER feedback even when logging is activated - I just get an empty set back without any error messages. This is a darn important feature.

UPDATE: I traced down the problem to a change in the Amplify library from a previous version. Before I only used the unauthorized access with customPrefix. For some reason the latest update assumed that I had an authorized access, so it was prepending the user identifier. My solution was to manually specify {level:“public”} in the options sent to the Amplify.Storage.XXX method.

@jtaylor1989 @elorzafe I’m horrified! So we have to call Storage.get() on EACH item to just to get the URI??? That’s expensive and poorly thought out, as i could have thousands of images whose URI i need to reference. Why can’t we use Storage.list() to get at these?

The uri of the image is surprisingly absent from the object item returned by Storage.list().

Only by calling Storage.get() on every item of the list that we will get the uri.

To list content, try similar code to the one below. Full code in my Github.

list

You can call your fetchImages in a componentDidMount() to display content.

componentDidMount = async () => { await this.fetchImages('images/', { level: "public" }) // (path, access) }