Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@stackone/file-picker

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stackone/file-picker

Navigate and select files from connected integrations

latest
Source
npmnpm
Version
0.7.1
Version published
Maintainers
3
Created
Source

StackOne File Picker

Allow your users to select files from your integrations. The @stackone/file-picker introduces an easy-to-use SDK to embed the StackOne file picker into your application.

Install

# NPM
npm install --save @stackone/file-picker

# Yarn
yarn add @stackone/file-picker

Usage

Initialize the File Picker with your options, and then call the open method to open the file picker. Listen to the callbacks to know when a file has been picked or whether the flow has been cancelled. The callback will give you the information about the file picked - you may also retrieve this information by using webhooks or the API. For example purposes, we used React as the framework, but you can use any framework built on top of Javascript/Typescript.

import { FilePicker } from '@stackone/file-picker';

export const FilePickerButton = () => {
  const [filePicker, setFilePicker] = useState<FilePicker | null> (null);

  useEffect(() => {
    const initializePicker = async () => {
      const { sessionToken } = await retrieveAPISessionToken();

      setFilePicker(new FilePicker({ sessionToken }));
    };

    initializePicker();
  }, []);

  const handleClick = useCallback(() => {
    filePicker?.open();
  }, [filePicker]);

  return (
    <button onClick={handleClick} disabled={!filePicker}>
      Open File Picker
    </button>
  );
};

File Picker Options

Apart from the sessionToken, you may pass a few options to customize the File Picker.

// Example of Options object
const options = {
    sessionToken = 'your-session-token',
    containerId = 'file-picker-container',
    baseUrl = 'https://app.stackone.com',
    fields = ['name', 'path', 'driveId'],
    showBranding = false,
    folderSelectionEnabled = true,
    driveSelectionEnabled = true,
    onFilesPicked = (data) => {
        // data may contain files, folders, and/or drives based on what was selected
        if (data.files) {
            console.log('Selected files:', data.files);
        }
        if (data.folders) {
            console.log('Selected folders:', data.folders);
        }
        if (data.drives) {
            console.log('Selected drives:', data.drives);
        }
    },
    onOpen = () => {
            console.log('File picker opened');
        },
    onClose = () => {
        console.log('File picker closed');
    },
    onCancel = () => {
        console.log('File selection canceled');
    }
};

const filePicker = new FilePicker(options);
NameTypeRequiredDescription
sessionTokenstringYesAPI session token created in the backend. The session token allows users to have access to their file picker integration.
containerIdstringNoID of the container element where the file picker will be mounted.
baseUrlstringNoWhich API instance should it connect to.
fieldsstring[]NoWhich fields from the raw picked file will be mapped on the files picked callback.
showBrandingbooleanNoShow StackOne footer on the file picker, it is defaulted to true.
folderSelectionEnabledbooleanNoEnable the selection of folders on the unified and native pickers.
driveSelectionEnabledbooleanNoEnable the selection of drives on the unified and native pickers.
onFilesPickedfunctionNoCalled when files are selected.
onOpen()functionNoCalled when the file picker is opened.
onClose()functionNoCalled every time the file picker is closed regardless of whether a file has been picked or not.
onCancel()functionNoCalled when the file picker is closed without a file being selected.
onError()functionNoCalled when the file picker has an error.

Callback Data Structure

When you get the callback from the onFilesPicked function, you will receive an object that may contain one or more of the following properties based on what was selected:

  • files (optional): An array of selected files
  • folders (optional): An array of selected folders when folderSelectionEnabled is true
  • drives (optional): An array of selected drives/sites when driveSelectionEnabled is true

Note: The callback will only include the arrays that have items. For example, if only files are selected, only the files property will be present.

File and Folder Types

Files and folders share the same structure:

NameTypeRequiredDescription
idstringYesThe Unified Id for the file.
namestringNoThe name of the file or folder.
pathstringNoThe URL or path of the file or folder.
driveIdstringNoThe Drive ID where the file or folder is located.

Drive Type

Drives have a different structure:

NameTypeRequiredDescription
idstringYesThe Unified Id for the drive.
namestringNoThe name of the drive or site.
typestringNoWill be 'site' for drives.
createdAtstringNoThe creation date of the drive.

Contribute & Release

This repose uses conventional commit. The repo use semantic-release and the package version is automatically determined based on the commit messages.

Release

Use the Manual release workflow to trigger a release. The package version and changelog will automatically be generated based on conventional commits.

FAQs

Package last updated on 03 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts