Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.
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
31 changes: 27 additions & 4 deletions lib/podio.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var util = require('util');
var events = require('events');
var FormData = require('form-data');
var fs = require('fs');

function Podio() {
this.https = require('https');
Expand Down Expand Up @@ -47,6 +49,19 @@ Podio.prototype.request = function(method, url, attributes, options, callback) {
if (method === 'GET' || method === 'DELETE') {
url = url + self.stringify(attributes);
}
else if(options.upload === true) {
http_body = new FormData();
if(attributes['source'])
{
http_body.append('source', fs.createReadStream(attributes['source']));
}
if(attributes['filename'])
{
http_body.append('filename', attributes['filename']);
}
delete headers['Content-Type'];
headers = http_body.getHeaders(headers);
}
else if (method === 'POST' || method === 'PUT') {
if (options.isOauth === true) {
http_body = self.stringify(attributes);
Expand Down Expand Up @@ -133,10 +148,18 @@ Podio.prototype.request = function(method, url, attributes, options, callback) {
self.emit('error', err);
});

if(http_body) {
apiRequest.write(http_body, 'utf8');
}
apiRequest.end();
if(options['upload'] === true)
{
http_body.getLength(function(err, length) {
apiRequest.setHeader('Content-Length', length);
http_body.pipe(apiRequest);
});
} else {
if (http_body) {
apiRequest.write(http_body, 'utf8');
}
apiRequest.end();
}
};

Podio.prototype.get = function(url, attributes, options, callback) {
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "0.1.0",
"description": "Nodejs wrapper for the Podio API",
"main": "lib/podio.js",
"dependencies": {
"form-data": "^0.1.4"
},
"repository": {
"type": "git",
"url": "http://github.com/haugstrup/podiojs"
Expand Down