Skip to content

Commit 097676f

Browse files
committed
fix: multipart fixes
1 parent 0816251 commit 097676f

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/https.android.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ export function request(opts: Https.HttpsRequestOptions): Promise<Https.HttpsRes
211211
request.url(opts.url);
212212

213213
if (opts.headers) {
214+
console.log('adding request header', opts.headers)
214215
Object.keys(opts.headers).forEach(key => request.addHeader(key, opts.headers[key] as any));
215216
}
216217

@@ -248,8 +249,10 @@ export function request(opts: Https.HttpsRequestOptions): Promise<Https.HttpsRes
248249
if (type === 'multipart/form-data') {
249250
let builder = new okhttp3.MultipartBody.Builder();
250251
builder.setType(MEDIA_TYPE);
251-
Object.keys(opts.body).forEach(k=>{
252-
const param =opts.body[k] as Https.HttpsFormDataParam;
252+
253+
(opts.body as Https.HttpsFormDataParam[]).forEach(param=>{
254+
// const param =opts.body[k] as Https.HttpsFormDataParam;
255+
console.log('handling multipart2', param.parameterName, param.data,param.fileName, param.contentType)
253256
if (param.fileName && param.contentType) {
254257
const MEDIA_TYPE = okhttp3.MediaType.parse(param.contentType);
255258
builder.addFormDataPart(param.parameterName, param.fileName, okhttp3.RequestBody.create(MEDIA_TYPE, param.data));

src/https.common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface HttpsRequestOptions {
3232
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD';
3333
headers?: Headers;
3434
params?: HttpsRequestObject;
35-
body?: HttpsRequestObject;
35+
body?: HttpsRequestObject | HttpsFormDataParam[];
3636
content?: string;
3737
/**
3838
* On Android large responses may crash the app (fi. https://httpbin.org/bytes/10000).

src/https.ios.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ export function request(opts: Https.HttpsRequestOptions): Promise<Https.HttpsRes
188188
switch(opts.method) {
189189
case 'POST' :
190190
manager.POSTParametersConstructingBodyWithBlockSuccessFailure(opts.url, null,(formData)=>{
191-
Object.keys(opts.body).forEach(k=>{
192-
const param =opts.body[k] as Https.HttpsFormDataParam;
191+
(opts.body as Https.HttpsFormDataParam[]).forEach(param=>{
192+
// const param =opts.body[k] as Https.HttpsFormDataParam;
193193
if (param.fileName && param.contentType) {
194194
formData.appendPartWithFileDataNameFileNameMimeType(param.data, param.parameterName, param.fileName, param.contentType);
195195
} else {

0 commit comments

Comments
 (0)