Created
March 29, 2011 15:30
-
-
Save ralphholzmann/892564 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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