Skip to content

Commit 3fdbd94

Browse files
committed
fix: some multi part fixes
1 parent ea415cd commit 3fdbd94

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/https.android.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ export function createRequest(
491491
: "application/json";
492492
const MEDIA_TYPE = okhttp3.MediaType.parse(type);
493493
let okHttpBody: okhttp3.RequestBody;
494-
if (type === "multipart/form-data") {
494+
if (type.startsWith("multipart/form-data")) {
495495
let builder = new okhttp3.MultipartBody.Builder();
496496
builder.setType(MEDIA_TYPE);
497497

src/https.ios.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,11 @@ export function createRequest(
567567
const failure = function (task: NSURLSessionDataTask, error: any) {
568568
AFFailure(resolve, reject, task, error, useLegacy, opts.url);
569569
};
570-
if (type === "multipart/form-data") {
570+
if (type.startsWith("multipart/form-data")) {
571571
switch (opts.method) {
572572
case "POST":
573+
// we need to remove the Content-Type or the boundary wont be set correctly
574+
headers.removeObjectForKey("Content-Type");
573575
task = manager.POSTParametersHeadersConstructingBodyWithBlockProgressSuccessFailure(
574576
opts.url,
575577
null,
@@ -581,12 +583,22 @@ export function createRequest(
581583
param.fileName &&
582584
param.contentType
583585
) {
584-
formData.appendPartWithFileDataNameFileNameMimeType(
585-
param.data,
586-
param.parameterName,
587-
param.fileName,
588-
param.contentType
589-
);
586+
if (param.data instanceof NSURL) {
587+
formData.appendPartWithFileURLNameFileNameMimeTypeError(
588+
param.data,
589+
param.parameterName,
590+
param.fileName,
591+
param.contentType
592+
);
593+
} else {
594+
// console.log('addding file data', param.data instanceof NSData);
595+
formData.appendPartWithFileDataNameFileNameMimeType(
596+
param.data,
597+
param.parameterName,
598+
param.fileName,
599+
param.contentType
600+
);
601+
}
590602
} else {
591603
formData.appendPartWithFormDataName(
592604
NSString.stringWithString(

0 commit comments

Comments
 (0)