Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions android/capacitor/src/main/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ var nativeBridge = (function (exports) {
const newFormData = [];
for (const pair of formData.entries()) {
const [key, value] = pair;
if (value instanceof File) {
if (value instanceof Blob) {
const base64File = await readFileAsBase64(value);
newFormData.push({
key,
value: base64File,
type: 'base64File',
contentType: value.type,
fileName: value.name,
fileName: value.name || 'blob',
});
}
else {
Expand Down Expand Up @@ -128,7 +128,7 @@ var nativeBridge = (function (exports) {
type: 'formData',
};
}
else if (body instanceof File) {
else if (body instanceof Blob) {
const fileData = await readFileAsBase64(body);
return {
data: fileData,
Expand Down
8 changes: 4 additions & 4 deletions core/native-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { CapacitorException } from './src/util';
// eslint-disable-next-line
let dummy = {};

const readFileAsBase64 = (file: File): Promise<string> =>
const readFileAsBase64 = (file: Blob): Promise<string> =>
new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onloadend = () => {
Expand All @@ -34,14 +34,14 @@ const convertFormData = async (formData: FormData): Promise<any> => {
const newFormData: CapFormDataEntry[] = [];
for (const pair of formData.entries()) {
const [key, value] = pair;
if (value instanceof File) {
if (value instanceof Blob) {
const base64File = await readFileAsBase64(value);
newFormData.push({
key,
value: base64File,
type: 'base64File',
contentType: value.type,
fileName: value.name,
fileName: (value as any).name || 'blob',
});
} else {
newFormData.push({ key, value, type: 'string' });
Expand Down Expand Up @@ -110,7 +110,7 @@ const convertBody = async (
data: await convertFormData(body),
type: 'formData',
};
} else if (body instanceof File) {
} else if (body instanceof Blob) {
const fileData = await readFileAsBase64(body);
return {
data: fileData,
Expand Down
6 changes: 3 additions & 3 deletions ios/Capacitor/Capacitor/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ var nativeBridge = (function (exports) {
const newFormData = [];
for (const pair of formData.entries()) {
const [key, value] = pair;
if (value instanceof File) {
if (value instanceof Blob) {
const base64File = await readFileAsBase64(value);
newFormData.push({
key,
value: base64File,
type: 'base64File',
contentType: value.type,
fileName: value.name,
fileName: value.name || 'blob',
});
}
else {
Expand Down Expand Up @@ -128,7 +128,7 @@ var nativeBridge = (function (exports) {
type: 'formData',
};
}
else if (body instanceof File) {
else if (body instanceof Blob) {
const fileData = await readFileAsBase64(body);
return {
data: fileData,
Expand Down