GithubHelp home page GithubHelp logo

harrisoff / onedrive-js-sdk Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 5.0 211 KB

Wraps some of OneDrive's APIs, only for uploading and sharing files.

License: MIT License

TypeScript 100.00%
onedrive onedrive-api onedrive-sdk imagehost image-hosting

onedrive-js-sdk's Introduction

OneDrive JS SDK

ts npm version license

This project wraps a small part of OneDrive's APIs, only for uploading files and creating sharing links.

You can build a webGUI to use it. There is an example OneDrive Image Hosting.

中文文档

Configure Account

In App registrations page click new registration button, then you'll need to fill the following fields:

  • Name

  • Supported account types

    Personal Microsoft accounts only is enough for personal usage

  • Redirect URI

    For example, https://localhost:3000/

After registration, click Authentication on the left, check Access tokens (used for implicit flows) and save.

Application (client) ID is generated once the application is registered. But you'll need to verify the application before using it. Just click Branding on the left and follow the instructions.

Usage

Authentication

Here we use token flow in authentication. Use helper function generateAuthUrl to generate an auth url and open it.

import { generateAuthUrl } from '@harrisoff/onedrive-js-sdk'

const authUrl = generateAuthUrl('your-client-id', 'your-redirect-uri')

Actually there's another field scope is required in the auth url. This value is set to openid https://graph.microsoft.com/Files.ReadWrite.All and is unnecessary to be changed.

After redirecting back to your site, access_token or error messages will be presented in the hash depending on whether authentication is successful.

API calls

There are two ways to call APIs.

The original APIs are exposed so you can use them directly:

import { uploadSmall, createUploadSession, uploadLargeChunk, share, getShareUrl } from '@harrisoff/onedrive-js-sdk'

Or you can use constructor to create a client instance, which wraps the original APIs:

import OneDriveAPI, { getShareUrl } from '@harrisoff/onedrive-js-sdk'

const client = new OneDriveApi({ accessToken })
const { id: fileId } = await client.upload(file, filePath)
const { shareId } = await client.share(fileId)
const sharingLink = getShareUrl(shareId)

TODO List

  • progress callback

Development

For more details, see:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.