Kloudless File Picker with root_folder_id

This is an example using the root_folder_id to only select files in the primary document library in a SharePoint site collection.

by kloudless

HTML

<script src="https://static-cdn.kloudless.com/p/platform/sdk/kloudless.explorer.js"></script>
<!DOCTYPE html>

<h1>The Kloudless File Picker JS library</h1>
<hr />

<p>
  This is an example using the root_folder_id to only select files in the primary document library in a SharePoint site collection.
</p>

<h2>Example</h2>
<p>
  Click a button below to launch the Chooser.
  Accounts are not persisted to demonstrate the addAccount() functionality.
</p>

<button id="chooser">Choose a file</button>

<h3>File information</h3>
<div id="file-info"><pre>Result will appear here</pre></div>

CSS

button {
  height: 40px;
  margin: 10px;
  font-size: 16px;
  border-radius: 5px;
  cursor: pointer;
}

JavaScript

var picker = window.Kloudless.filePicker.picker({
  app_id: 'iCZ_ICMy43H0NSoz0QbLvmyjzCHf2frAOPaBfWVgh9_vrFIM',
  multiselect: true,
  computer: true,
  services: ["sharepoint", "dropbox"],
  persist: "none" // Just used for testing
});

// Chooser
picker.on('success', function(files) {
  $("#file-info > pre").replaceWith(
    '<pre>' +
    JSON.stringify(files, null, 2) +
    '</pre>');
});
picker.choosify($('#chooser'));

var root_folder_id = {};

picker.on('addAccount', account => {
  // Set `retrieve_token: true` in the config to retrieve the Bearer token
  // to use in API requests to determine the right root folder ID, and
  // then include that root folder ID below.
  if (account.service == 'sharepoint') {
    root_folder_id[account.id] = 'folder_OmdldGZvbGRlcmJ5c2VydmVycmVsYXRpdmVwYXRoKGRlY29kZWR1cmw9J3NoYXJlZCBkb2N1bWVudHMnKQ';
    picker.update({
      root_folder_id: root_folder_id
    });
  }
});