Skip to content

Commit 486f83f

Browse files
committed
fix: form data supports File type
1 parent 29b178e commit 486f83f

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/https/request.android.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr
518518
if (param.fileName && param.contentType) {
519519
if (param.data instanceof okhttp3.RequestBody) {
520520
builder.addFormDataPart(param.parameterName, param.fileName, param.data);
521+
} else if (param.data instanceof File) {
522+
builder.addFormDataPart(param.parameterName, param.fileName, okhttp3.RequestBody.create(new java.io.File(param.data.path), okhttp3.MediaType.parse(param.contentType)));
521523
} else {
522524
let nData = param.data;
523525
if (param.data instanceof ArrayBuffer) {

src/https/request.ios.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr
460460
if (param.fileName && param.contentType) {
461461
if (param.data instanceof NSURL) {
462462
formData.appendPartWithFileURLNameFileNameMimeTypeError(param.data, param.parameterName, param.fileName, param.contentType);
463+
} else if (param.data instanceof File) {
464+
formData.appendPartWithFileURLNameFileNameMimeTypeError(NSURL.fileURLWithPath(param.data.path), param.parameterName, param.fileName, param.contentType);
463465
} else {
464466
let data = param.data;
465467
if (typeof data === 'string') {

0 commit comments

Comments
 (0)