nuxeo/onedrive-file-picker

Name: onedrive-file-picker

Owner: Nuxeo

Description: JavaScript file picker for OneDrive & OneDrive for Business

Created: 2016-02-18 14:41:10.0

Updated: 2016-09-07 03:09:51.0

Pushed: 2016-08-24 14:55:22.0

Homepage: null

Size: 105

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

File picker for OneDrive & OneDrive for Business

The OneDrive & OneDrive for Business file picker is a light JavaScript picker over the OneDrive REST API. It is designed to work with both OneDrive & OneDrive for Business and to have light dependencies. Check your live demo.

Getting Started

Download the latest release here or build it from master.

You also need jQuery in your page. The file picker was built with jQuery 1.8.0, it should work with lower version.

Then include jQuery and file picker scripts in your page :

ipt type="text/javascript" src="https://code.jquery.com/jquery-1.8.0.min.js"></script>
ipt type="text/javascript" src="onedrive-file-picker.js"></script>
k rel="stylesheet" type="text/css" href="onedrive-file-picker.css">
Get your access token

You can follow the OneDrive documentation page to obtain an access token. This part has to be done by your application, as the file picker needs an access token to work.

OneDrive

For OneDrive just init the file picker with access token :

accessToken = '...';
picker = new OneDriveFilePicker({ 'accessToken': accessToken });
OneDrive for Business

For OneDrive for Business, the file picker needs an access token and the resource url to access the api.

accessToken = '...';
baseURL = 'https://{tenant}-my.sharepoint.com/_api/v2.0'; // For example : https://nuxeo-my.sharepoint.com/_api/v2.0
picker = new OneDriveFilePicker({ 'accessToken': accessToken, 'baseURL': baseURL });
Open file picker and get selected file

Once you have your file picker instance, you can call select method to open it. The method return a Promise, if you're not familiar with it, see this page. Once user has selected a file or closed the picker, the Promise will be resolved.

er.select().then(function(result) {
 Your code here

You get an object with at least action attribute which could be :

You can also catch error thrown from API, like unauthorized errors, with catch Promise method :

er.select().catch(function(error) {
 Your code here

The API error contains the textual portion of the HTTP status, such as “Not Found” or “Internal Server Error.”

Contributing

See our contribution documentation.

Requirements
Setup

Install Node.js and then use npm to install all the required libraries:

t clone https://github.com/nuxeo/onedrive-file-picker
 onedrive-file-picker
m install
Demo

You can run a live demo during development with hot reload, just enter in your terminal :

lp demo

Licensing

Apache License, Version 2.0

About Nuxeo

Nuxeo dramatically improves how content-based applications are built, managed and deployed, making customers more agile, innovative and successful. Nuxeo provides a next generation, enterprise ready platform for building traditional and cutting-edge content oriented applications. Combining a powerful application development environment with SaaS-based tools and a modular architecture, the Nuxeo Platform and Products provide clear business value to some of the most recognizable brands including Verizon, Electronic Arts, Sharp, FICO, the U.S. Navy, and Boeing. Nuxeo is headquartered in New York and Paris. More information is available at www.nuxeo.com.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.