Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to upload a file by passing a readable stream #98

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions lib/dbox.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var request = require("request")
var qs = require("querystring")
var path = require("path")
var request = require("request")
var qs = require("querystring")
var path = require("path")
var isStream = require("isstream")

exports.app = function(config){
var root = config.root || "sandbox"
Expand Down Expand Up @@ -185,15 +186,24 @@ exports.app = function(config){
path: path,
query: signature
})

var args = {
"method": "PUT",
"headers": { "content-length": body.length },
"url": url
"url": url,
body: body
}

// Is buffer or string not a stream
if (!isStream(body)) {

args.headers = { "content-length": body.length };

// Do not send empty body
if(body.length === 0) {
delete args.body;
}

}

// do not send empty body
if(body.length > 0) args["body"] = body

return request(args, function(e, r, b){
cb(e ? null : r.statusCode, e ? null : helpers.parseJSON(b))
Expand Down
131 changes: 101 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,120 @@
"version": "0.6.4",
"author": "Brock Whitten <[email protected]>",
"contributors": [
{ "name": "Brock Whitten", "email": "[email protected]" },
{ "name": "Anton Podviaznikov", "email": "[email protected]" },
{ "name": "Tom Gallacher", "email": "[email protected]" },
{ "name": "Emmanuel Boudrant", "email": "[email protected]" },
{ "name": "Danny Amey", "email": "[email protected]" },
{ "name": "Michiel DeJong", "email": "[email protected]" },
{ "name": "Julien Cayzac", "email": "[email protected]" },
{ "name": "Aleksandar Kolundzija", "email": "[email protected]" },
{ "name": "Carl Sverre", "email": "[email protected]" },
{ "name": "Leonardo D. Schlossmacher", "email": "[email protected]" },
{ "name": "Sam Nguyen", "email": "[email protected]" },
{ "name": "Marak Squires", "email": "[email protected]" },
{ "name": "Paul Ledbetter", "email": "[email protected]" },
{ "name": "James Allen", "email": "[email protected]" },
{ "name": "Jesper Lindstrøm Nielsen", "email": "[email protected]" },
{ "name": "Rob Ellis", "email": "[email protected]" },
{ "name": "Jeremiah Condon", "email": "[email protected]" },
{ "name": "John Titus", "email": "[email protected]" },
{ "name": "Ben Buckman", "email": "[email protected]" },
{ "name": "Zach Ahn", "email": "[email protected]" }
{
"name": "Brock Whitten",
"email": "[email protected]"
},
{
"name": "Anton Podviaznikov",
"email": "[email protected]"
},
{
"name": "Tom Gallacher",
"email": "[email protected]"
},
{
"name": "Emmanuel Boudrant",
"email": "[email protected]"
},
{
"name": "Danny Amey",
"email": "[email protected]"
},
{
"name": "Michiel DeJong",
"email": "[email protected]"
},
{
"name": "Julien Cayzac",
"email": "[email protected]"
},
{
"name": "Aleksandar Kolundzija",
"email": "[email protected]"
},
{
"name": "Carl Sverre",
"email": "[email protected]"
},
{
"name": "Leonardo D. Schlossmacher",
"email": "[email protected]"
},
{
"name": "Sam Nguyen",
"email": "[email protected]"
},
{
"name": "Marak Squires",
"email": "[email protected]"
},
{
"name": "Paul Ledbetter",
"email": "[email protected]"
},
{
"name": "James Allen",
"email": "[email protected]"
},
{
"name": "Jesper Lindstrøm Nielsen",
"email": "[email protected]"
},
{
"name": "Rob Ellis",
"email": "[email protected]"
},
{
"name": "Jeremiah Condon",
"email": "[email protected]"
},
{
"name": "John Titus",
"email": "[email protected]"
},
{
"name": "Ben Buckman",
"email": "[email protected]"
},
{
"name": "Zach Ahn",
"email": "[email protected]"
},
{
"name": "Mohammad Fares",
"email": "[email protected]"
}
],
"keywords": [
"dropbox",
"sdk",
"s3"
],
"keywords": ["dropbox", "sdk", "s3"],
"main": "./lib/dbox.js",
"scripts": {
"test": "./node_modules/.bin/mocha -t 120000 test/all.js -R spec"
"test": "./node_modules/.bin/mocha -t 120000 test/all.js -R spec"
},
"repository": {
"repository": {
"type": "git",
"url": "https://github.com/sintaxi/node-dbox.git"
},
"dependencies": {
"request": "2.9.153"
"isstream": "^0.1.2",
"request": "^2.72.0"
},
"devDependencies": {
"devDependencies": {
"mocha": "1.21.4",
"should": "4.0.4",
"prompt": "0.1.12"
},
"engines": { "node": "*" },
"licenses" : [
{
"type" : "MIT",
"url" : "https://raw.github.com/sintaxi/node-dbox/master/README.md"
"engines": {
"node": "*"
},
"licenses": [
{
"type": "MIT",
"url": "https://raw.github.com/sintaxi/node-dbox/master/README.md"
}
]
}