amazon-s3aws-amplifyamplifyjsaws-amplify-sdk-js

Storage.list() returning an empty array


I am trying to make a webpage to view all of the files in a Cognito accounts private folder in S3. I'm using the Amplify Auth and Storage plugins, and I know they are both configured properly because I already have file upload working. I found this thread on Github issues, but none of what is mentioned in that thread helped me. With the debug logs, I can see that it is properly resolving the path, as I am getting the correct path shown, but only an empty array is being returned. I've even tried resolving the public folder, which has a test file in it just to make sure its not an access thing, but that has the exact same issue.

This is the correct path its looking up, with xxxx replacing the account ID. [DEBUG] 58:16.450 AWSS3Provider - list * from downloads/us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/*

const downloadPrefix = {
    private: 'downloads/',
};
Auth.currentCredentials();
    Storage.list('*', {
        level: 'private',
        customPrefix: downloadPrefix
    })
    .then(result => {
        this.message = result.length
    })
    .catch(err => {
        this.message = err
    }
);

Thanks in advance for any help you may be able to provide! I've been stuck on this all day.


Solution

  • I figured it out. Removing the * in the search term made it actually return results, which is not at all what I would have expected, and should have tried to begin with. Storage.list('', ....) should fix your problem if you're doing the same thing as I am.