Listing User Docs
The following example lists the documents for a user.
Choose Copy
to save the code locally, or see the link to the complete
example at the end of this topic.
Require the AWS SDK for Ruby module.
require 'aws-sdk-workdocs' # v2: require 'aws-sdk'
Create a helper method to get the root folder of a user.
def get_user_folder(client, orgId, user_email) root_folder = '' resp = client.describe_users({ organization_id: orgId, }) # resp.users should have only one entry resp.users.each do |user| if user.email_address == user_email root_folder = user.root_folder_id end end return root_folder end
Create a Amazon WorkDocs client.
client = Aws::WorkDocs::Client.new(region: 'us-west-2')
Get the root folder for that user.
# Set to the email address of a user user_email = 'someone@somewhere' # Set to the OrganizationId of your WorkDocs site. orgId = 'd-123456789c' user_folder = get_user_folder(client, orgId, user_email)
Call describe_folder_contents
to get the contents of the folder
in ascending order.
resp = client.describe_folder_contents({ folder_id: user_folder, # required sort: "NAME", # accepts DATE, NAME order: "ASCENDING", # accepts ASCENDING, DESCENDING })
Display the name, size (in bytes), last modified date, document ID and version ID for each document in the user's root folder.
resp.documents.each do |doc| md = doc.latest_version_metadata puts "Name: #{md.name}" puts "Size (bytes): #{md.size}" puts "Last modified: #{doc.modified_timestamp}" puts "Doc ID: #{doc.id}" puts "Version ID: #{md.id}" puts end
See the complete example on GitHub.