Skip to content

Instantly share code, notes, and snippets.

@ralphholzmann
Created March 29, 2011 15:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralphholzmann/892564 to your computer and use it in GitHub Desktop.
Save ralphholzmann/892564 to your computer and use it in GitHub Desktop.
DropboxClient.prototype.putFile = function(file, path, optargs, cb) {
if (typeof optargs == 'function') cb = optargs, optargs = {};
var boundary = 'sAxIqse3tPlHqUIUI9ofVlHvtdt3tpaG',
content_type = 'multipart/form-data; boundary=' + boundary,
self = this;
require('fs').readFile(file, function (err, data) {
if (err) return cb(err);
// Build request body.
path = escapePath(path);
var body = '--' + boundary + '\r\n' +
'Content-Disposition: form-data; name=file; filename=' + file +
'\r\n' + 'Content-type: application/octet-stream\r\n' +
/**/
'\r\n' + data.toString('binary') + '\r\n' + '--' + boundary + '--';
/**/
self.oauth.post(CONTENT_API_URI + '/files/' + self.type + '/' + path +
'?file=' + file,
optargs.token || self.access_token,
optargs.secret || self.access_token_secret,
body, content_type,
function(err, data, res) {
if (err) cb(err);
else cb(null, JSON.parse(data));
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment