Skip to content

Commit ee850ac

Browse files
Sander van Zoestmarkstos
authored andcommitted
Fix uploads
1 parent 9e37ee1 commit ee850ac

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

lib/httpClient.js

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const Promise = require('bluebird')
33
const querystring = require('querystring')
44
const fs = require('fs')
55
const rateLimiting = require('./rateLimiting')
6-
const request = require('request-promise')
76

87
// request.debug = true
98

@@ -99,31 +98,21 @@ HttpClient.prototype.deleteEndpoint = function (endpoint, args, done) {
9998
}
10099

101100
//= ==== postUpload =====
102-
HttpClient.prototype.postUpload = function (args, done) {
103-
if (!args) {
104-
args = {}
105-
}
106-
101+
HttpClient.prototype.postUpload = function (args = {}, done) {
107102
var options = {
108103
url: 'uploads',
109-
method: 'POST'
104+
method: 'POST',
105+
formData: {
106+
...args.formData,
107+
file: fs.createReadStream(args.file)
108+
}
110109
}
111110

112111
if (args.access_token) {
113112
options.headers = { Authorization: 'Bearer ' + args.access_token }
114113
}
115114

116-
var req = request.post(options, function (err, httpResponse, payload) {
117-
done(err, payload)
118-
})
119-
120-
var form = req.form()
121-
122-
// append the rest of the formData values
123-
for (var key in args.formData) {
124-
form.append(key, args.formData[key])
125-
}
126-
form.append('file', fs.createReadStream(args.file))
115+
return Promise.resolve(this.request.post(options)).asCallback(done)
127116
}
128117

129118
//= ==== get pagination query string =====
@@ -199,7 +188,8 @@ HttpClient.prototype._requestHelper = function (options, done) {
199188
// The newer promise-bsed API updates a global rateLimiting counter
200189
limits = rateLimiting.updateRateLimits(response.headers)
201190
return Promise.resolve(response.body)
202-
}).asCallback(callback)
191+
})
192+
.asCallback(callback)
203193
}
204194

205195
//= ==== helpers =====

lib/uploads.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var uploads = function (client) {
2-
this.client = this
2+
this.client = client
33
}
44

55
var _allowedFormProps = [
@@ -11,7 +11,7 @@ var _allowedFormProps = [
1111
'data_type'
1212
]
1313

14-
uploads.post = function (args, done) {
14+
uploads.prototype.post = function (args, done) {
1515
var self = this
1616

1717
// various requirements
@@ -42,7 +42,7 @@ uploads.post = function (args, done) {
4242
})
4343
}
4444

45-
uploads._check = function (args, cb) {
45+
uploads.prototype._check = function (args, cb) {
4646
var endpoint = 'uploads'
4747
var self = this
4848

@@ -61,7 +61,7 @@ uploads._check = function (args, cb) {
6161
})
6262
}
6363

64-
uploads._uploadIsDone = function (args) {
64+
uploads.prototype._uploadIsDone = function (args) {
6565
var isDone = false
6666

6767
switch (args.status) {

0 commit comments

Comments
 (0)