Giter Site home page Giter Site logo

node-dropbox's Introduction

Node Dropbox

A simple node.js API client for the Dropbox API.

Installation

npm install node-dropbox --save

Usage:

Before starting anything you need to go create your app over at: https://www.dropbox.com/developers/apps then go ahead and grab your Key and Secret.

Authentication

Just use the Authenticate method to generate a url for your user to go to. This will be redirected back to another page.

var node_dropbox = require('node-dropbox');
node_dropbox.Authenticate('key', 'secret', 'redirect_url', function(err, url){
	// redirect user to the url.
	// looks like this: "https://www.dropbox.com/1/oauth2/authorize?client_id=<key_here>&response_type=code&redirect_uri=<redirect_url_here>"
});

On the page where you redirected to, you will need to use the AccessToken method to get the users access token for api use. The redirect_url this time is only for validation, it will not need to redirect again.

node_dropbox.AccessToken('key', 'secret', 'access_code', 'redirect_url', function(err, body) {
	access_token = body.access_token;
});

Make API Calls

When you have the access token in hand, all you need to do is make api calls. That's all it takes to get started with this client.

api = node_dropbox.api(access_token);
api.account(function(err, res, body) {
	console.log(body);
});

The above output will be something like:

{
"referral_link": "https://www.dropbox.com/referrals/r1a2n3d4m5s6t7",
"display_name": "John P. User",
"uid": 12345678,
"team": {
    "name": "Acme Inc."
},
"country": "US",
"quota_info": {
    "shared": 253738410565,
    "quota": 107374182400000,
    "normal": 680031877871
}
}

Available API Calls:

api.account(callback); // Fetches the account information.
api.createDir(path, callback); // Creates a directory.
api.removeDir(path, callback); // Deletes a directory.
api.createFile(path, contents, callback); // Creates a new file.
api.removeFile(path, callback) // Deletes a file.
api.moveSomething(from_path, to_path, callback); // Moves/renames a file.
api.getMetadata(path, callback) // Retrieves file and folder metadata. Can be used to list a folder's content.
api.getFile(path, callback) // Downloads a file.
api.getDelta(cursor, path, callback) // Gets changes to files and folders in a user's Dropbox.

// Each callback will return the error message, response, and body(json data).
api.account(function(error, response, body){
	console.log(body.display_name);
});

Planned Features:

I plan on implementing the Dropbox Core API features(https://www.dropbox.com/developers/core/docs) and revamping the code a little bit to make it integrate with express easily or possibly just make it more friendly to use. Right now, it's not the best, but it works.

node-dropbox's People

Contributors

crackerakiua avatar eragonj avatar g33kidd avatar lexoyo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

node-dropbox's Issues

Is it possible to specify a mime type for newly created files?

I've got a base64 image representation that I want to save to my dropbox. I've tried stripping the irrelevant bits and manually writing a png using that string. But the files are always corrupted. When I look at the the dropbox-js I noticed that you can manually specify mime types.

thanks again!

write file to disk

Hey!
Thanks for that great module.
I am having trouble to download a file using the getFile method.
It just creates an empty file.

here is my code:

api.getFile('/personal/1.jpg', function(err, res, body) {

    var file = fs.createWriteStream("1.jpg");
    res.pipe(file);

});

Read all folders.

Is there a better way to list all folders in the dropbox from use getMetadata and then for each folder in it use again getMetadata ?

its not uploading the file completely, we need a `Size` parameter.

HI devs,
@EragonJ @elarnellis @lexoyo @g33kidd @CrackerakiUA

I want to upload a file successfully, but it's not uploading completely. and there is no parameter to pass the file size.

the problem is: I'm trying to upload an 115KB file, it uploads only 15KB.
My code is :

let fileStream = fs.createReadStream("./upload/1-T-9cE7LBAwFEdE7V-67eDg.jpeg");
  let size = fs.statSync("./upload/1-T-9cE7LBAwFEdE7V-67eDg.jpeg").size;
api.createFile("/1-T-9cE7LBAwFEdE7V-67eDg.jpeg", fileStream, function(err, res, body) {
        console.log(err, res);
});

Refactoring with ES6

Just going to rewrite some of the code and restructure things a bit. Maybe use different libraries and make it more modular. Not quite sure. It could split off into a different package in the future.

error: 'v1_retired'

when I used getMetadata method of node_dropbox dependencies to retrieves files and folder, getting error " error: 'v1_retired'" in getMetadata response.
How to solve this error? Please give us solution asap.

Error in generating Access token

Hi,

I am getting Error: read ECONNRESET on node_dropbox.AccessToken(config.dropbox_key, config.dropbox_secret, config.dropbox_accessCode, config.dropbox_redirectUri, function(err, tokens) {}

Please let me know why this error is occured

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.