Fix multipart for requests, fixes #675

This commit is contained in:
Amish Shah
2016-09-10 12:40:45 +01:00
parent 84fe65ec78
commit 4255dcd3ca
3 changed files with 11 additions and 4 deletions

View File

@@ -28,10 +28,16 @@ class APIRequest {
const apiRequest = request[this.method](this.url);
if (this.auth) apiRequest.set('authorization', this.getAuth());
if (this.file && this.file.file) {
apiRequest.set('Content-Type', 'multipart/form-data');
apiRequest.attach('file', this.file.file, this.file.name);
this.data = this.data || {};
for (const key in this.data) {
if (this.data[key]) {
apiRequest.field(key, this.data[key]);
}
}
} else if (this.data) {
apiRequest.send(this.data);
}
if (this.data) apiRequest.send(this.data);
apiRequest.set('User-Agent', this.rest.userAgentManager.userAgent);
return apiRequest;
}