Skip to content

Commit a135841

Browse files
committed
fix: Handle body types properly if not JSON ie formData
fixes: #355
1 parent 2de6c3e commit a135841

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/infrastructure/KyRequester.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Ky from 'ky-universal';
2+
import FormData from 'form-data';
23
import { decamelizeKeys } from 'humps';
34
import { stringify } from 'query-string';
45
import { skipAllCaps } from './Utils';
@@ -22,6 +23,10 @@ function defaultRequest(service: any, { body, query, sudo, method }) {
2223
const headers = new Headers(service.headers);
2324

2425
if (sudo) headers.append('sudo', `${sudo}`);
26+
27+
if (typeof body === 'object' && !(body instanceof FormData)){
28+
body = JSON.stringify(decamelizeKeys(body, skipAllCaps));
29+
}
2530

2631
return {
2732
timeout: service.requestTimeout,
@@ -30,7 +35,7 @@ function defaultRequest(service: any, { body, query, sudo, method }) {
3035
onProgress: (method === 'stream') ? () => {} : undefined,
3136
searchParams: stringify(decamelizeKeys(query || {}) as any, { arrayFormat: 'bracket' }),
3237
prefixUrl: service.url,
33-
json: typeof body === 'object' ? decamelizeKeys(body, skipAllCaps) : body,
38+
body,
3439
rejectUnauthorized: service.rejectUnauthorized,
3540
}
3641
}

src/services/ProjectImportExport.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ class ProjectImportExport extends BaseService {
1515
return RequestHelper.get(this, `projects/${pId}/export`, options);
1616
}
1717

18-
import(content: string, path: string, options?: Sudo) {
18+
import(content: string, path: string) {
1919
const form = new FormData();
2020

2121
form.append('file', content, {
2222
filename: path,
2323
contentType: 'application/octet-stream',
2424
});
2525

26-
return RequestHelper.post(this, 'projects/import', { ...options, form });
26+
return RequestHelper.post(this, 'projects/import', form);
2727
}
2828

2929
importStatus(projectId: ProjectId, options?: Sudo) {

src/services/Projects.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class Projects extends BaseService {
131131
return RequestHelper.put(this, `projects/${pId}/push_rule`, options);
132132
}
133133

134-
upload(projectId, content, metadata: ProjectUploadMetadata = {}, options?: Sudo) {
134+
upload(projectId, content, metadata: ProjectUploadMetadata = {}) {
135135
const pId = encodeURIComponent(projectId);
136136
const form = new FormData();
137137

@@ -142,7 +142,7 @@ class Projects extends BaseService {
142142

143143
form.append('file', content, Object.assign(defaultMetadata, metadata));
144144

145-
return RequestHelper.post(this, `projects/${pId}/uploads`, { ...options, form });
145+
return RequestHelper.post(this, `projects/${pId}/uploads`, form);
146146
}
147147
}
148148

0 commit comments

Comments
 (0)