Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

fix(mobile): upload failing in Android (#687)

Jibran Iqbal607ba9496c5e
diff --git a/apps/mobile/app.json b/apps/mobile/app.json
index fc7964f5..35492b9c 100644
--- a/apps/mobile/app.json
+++ b/apps/mobile/app.json
@@ -9,7 +9,8 @@
"userInterfaceStyle": "automatic",
"newArchEnabled": true,
"ios": {
- "supportsTablet": true
+ "supportsTablet": true,
+ "bundleIdentifier": "app.papra.ios"
},
"android": {
"adaptiveIcon": {
diff --git a/apps/mobile/app/ReactotronConfig.ts b/apps/mobile/app/ReactotronConfig.ts
new file mode 100644
index 00000000..fc50a1d7
--- /dev/null
+++ b/apps/mobile/app/ReactotronConfig.ts
@@ -0,0 +1,5 @@
+import Reactotron from 'reactotron-react-native';
+
+Reactotron.configure({ name: 'Papra' }) // controls connection & communication settings
+ .useReactNative() // add all built-in react native plugins
+ .connect(); // let's connect!
diff --git a/apps/mobile/app/index.tsx b/apps/mobile/app/index.tsx
index fa1e5cfb..358b98f6 100644
--- a/apps/mobile/app/index.tsx
+++ b/apps/mobile/app/index.tsx
@@ -3,6 +3,11 @@ import { Redirect } from 'expo-router';
import { createAuthClient } from '@/modules/auth/auth.client';
import { configLocalStorage } from '@/modules/config/config.local-storage';
+if (__DEV__) {
+ // eslint-disable-next-line ts/no-require-imports
+ require('./ReactotronConfig');
+}
+
export default function Index() {
const query = useQuery({
queryKey: ['api-server-url'],
diff --git a/apps/mobile/package.json b/apps/mobile/package.json
index 6342891c..49f7abbb 100644
--- a/apps/mobile/package.json
+++ b/apps/mobile/package.json
@@ -29,12 +29,13 @@
"better-auth": "catalog:",
"expo": "~54.0.22",
"expo-constants": "~18.0.10",
- "expo-document-picker": "^14.0.7",
+ "expo-document-picker": "^14.0.8",
"expo-file-system": "^19.0.19",
"expo-font": "~14.0.9",
"expo-haptics": "~15.0.7",
"expo-image": "~3.0.10",
"expo-linking": "~8.0.8",
+ "expo-network": "^8.0.8",
"expo-router": "~6.0.14",
"expo-secure-store": "^15.0.7",
"expo-sharing": "^14.0.7",
@@ -62,6 +63,7 @@
"eas-cli": "^16.27.0",
"eslint": "catalog:",
"eslint-config-expo": "~10.0.0",
+ "reactotron-react-native": "^5.1.18",
"typescript": "catalog:",
"vitest": "catalog:"
}
diff --git a/apps/mobile/src/modules/api/api.models.ts b/apps/mobile/src/modules/api/api.models.ts
index a521d4cf..6fd2635a 100644
--- a/apps/mobile/src/modules/api/api.models.ts
+++ b/apps/mobile/src/modules/api/api.models.ts
@@ -41,3 +41,9 @@ export function coerceDates<T extends Record<string, unknown>>(obj: T): CoerceDa
...('scheduledPurgeAt' in obj ? { scheduledPurgeAt: coerceDateOrUndefined(obj.scheduledPurgeAt) } : {}),
} as CoerceDates<T>;
}
+
+export type LocalDocument = {
+ uri: string;
+ name: string;
+ type: string | undefined;
+};
diff --git a/apps/mobile/src/modules/documents-actions/screens/document-view.screen.tsx b/apps/mobile/src/modules/documents-actions/screens/document-view.screen.tsx
index 846ae53d..3a14594e 100644
--- a/apps/mobile/src/modules/documents-actions/screens/document-view.screen.tsx
+++ b/apps/mobile/src/modules/documents-actions/screens/document-view.screen.tsx
@@ -198,7 +198,7 @@ function createStyles({ themeColors }: { themeColors: ThemeColors }) {
borderRadius: 20,
backgroundColor: themeColors.secondaryBackground,
justifyContent: 'center',
- alignItems: 'flex-start',
+ alignItems: 'center',
},
headerTitle: {
flex: 1,
diff --git a/apps/mobile/src/modules/documents/components/import-drawer.tsx b/apps/mobile/src/modules/documents/components/import-drawer.tsx
index c1a86940..2b832c47 100644
--- a/apps/mobile/src/modules/documents/components/import-drawer.tsx
+++ b/apps/mobile/src/modules/documents/components/import-drawer.tsx
@@ -1,6 +1,6 @@
+import type { LocalDocument } from '@/modules/api/api.models';
import type { ThemeColors } from '@/modules/ui/theme.constants';
import * as DocumentPicker from 'expo-document-picker';
-import { File } from 'expo-file-system';
import {
Modal,
StyleSheet,
@@ -58,12 +58,16 @@ export function ImportDrawer({ visible, onClose }: ImportDrawerProps) {
return;
}
- const [pickerFile] = result.assets;
+ const pickerFile = result.assets[0];
if (!pickerFile) {
return;
}
- const file = new File(pickerFile.uri);
+ const file: LocalDocument = {
+ uri: pickerFile.uri,
+ name: pickerFile.name,
+ type: pickerFile.mimeType,
+ };
await uploadDocument({ file, apiClient, organizationId: currentOrganizationId });
await queryClient.invalidateQueries({ queryKey: ['organizations', currentOrganizationId, 'documents'] });
diff --git a/apps/mobile/src/modules/documents/documents.services.ts b/apps/mobile/src/modules/documents/documents.services.ts
index cda7ec57..3fb8df9f 100644
--- a/apps/mobile/src/modules/documents/documents.services.ts
+++ b/apps/mobile/src/modules/documents/documents.services.ts
@@ -1,31 +1,37 @@
import type { ApiClient } from '../api/api.client';
-import type { CoerceDates } from '../api/api.models';
+import type { CoerceDates, LocalDocument } from '../api/api.models';
import type { AuthClient } from '../auth/auth.client';
import type { Document } from './documents.types';
import * as FileSystem from 'expo-file-system/legacy';
import { coerceDates } from '../api/api.models';
-export function getFormData(pojo: Record<string, string | Blob>): FormData {
+export function getFormData(pojo: Record<string, string | FormDataValue | Blob>): FormData {
const formData = new FormData();
Object.entries(pojo).forEach(([key, value]) => formData.append(key, value));
+
return formData;
}
export async function uploadDocument({
file,
organizationId,
-
apiClient,
}: {
- file: Blob;
+ file: LocalDocument;
organizationId: string;
-
apiClient: ApiClient;
}) {
const { document } = await apiClient<{ document: Document }>({
method: 'POST',
path: `/api/organizations/${organizationId}/documents`,
- body: getFormData({ file }),
+ body: getFormData({
+ file: {
+ uri: file.uri,
+ // to avoid %20 in file name it is issue in react native that upload file name replaces spaces with %20
+ name: file.name.replace(/ /g, '_'),
+ type: file.type ?? 'application/json',
+ },
+ }),
});
return {
diff --git a/apps/mobile/src/types/formdata.d.ts b/apps/mobile/src/types/formdata.d.ts
new file mode 100644
index 00000000..7a8d88e4
--- /dev/null
+++ b/apps/mobile/src/types/formdata.d.ts
@@ -0,0 +1,17 @@
+/* eslint-disable ts/consistent-type-definitions */
+/* eslint-disable ts/method-signature-style */
+
+// Source - https://stackoverflow.com/a
+// Posted by Patrick Roberts, modified by community. See post 'Timeline' for change history
+// Retrieved 2025-12-19, License - CC BY-SA 4.0
+
+interface FormDataValue {
+ uri: string;
+ name: string;
+ type: string;
+}
+
+interface FormData {
+ append(name: string, value: string | FormDataValue | Blob, fileName?: string): void;
+ set(name: string, value: string | FormDataValue | Blob, fileName?: string): void;
+}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 7ed63b83..52eb7958 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -134,7 +134,7 @@ importers:
dependencies:
'@better-auth/expo':
specifier: 'catalog:'
'@corentinth/chisels':
specifier: 'catalog:'
version: 2.1.0
@@ -169,8 +169,8 @@ importers:
specifier: ~18.0.10
expo-document-picker:
- specifier: ^14.0.7
- version: 14.0.7([email protected])
+ specifier: ^14.0.8
+ version: 14.0.8([email protected])
expo-file-system:
specifier: ^19.0.19
@@ -186,6 +186,9 @@ importers:
expo-linking:
specifier: ~8.0.8
+ expo-network:
+ specifier: ^8.0.8
expo-router:
specifier: ~6.0.14
version: 6.0.14(49a2902d0574a0052a669c80d9729e84)
@@ -262,6 +265,9 @@ importers:
eslint-config-expo:
specifier: ~10.0.0
+ reactotron-react-native:
+ specifier: ^5.1.18
typescript:
specifier: 'catalog:'
version: 5.9.3
@@ -397,7 +403,7 @@ importers:
version: 12.27.0
'@better-auth/expo':
specifier: 'catalog:'
'@cadence-mq/core':
specifier: ^0.2.1
version: 0.2.1
@@ -7339,8 +7345,8 @@ packages:
expo: '*'
react-native: '*'
- resolution: {integrity: sha512-81Jh8RDD0GYBUoSTmIBq30hXXjmkDV1ZY2BNIp1+3HR5PDSh2WmdhD/Ezz5YFsv46hIXHsQc+Kh1q8vn6OLT9Q==}
+ resolution: {integrity: sha512-3tyQKpPqWWFlI8p9RiMX1+T1Zge5mEKeBuXWp1h8PEItFMUDSiOJbQ112sfdC6Hxt8wSxreV9bCRl/NgBdt+fA==}
peerDependencies:
expo: '*'
@@ -7395,6 +7401,12 @@ packages:
react: '*'
react-native: '*'
+ resolution: {integrity: sha512-dgrL8UHAmWofqeY4UEjWskCl/RoQAM0DG6PZR8xz2WZt+6aQEboQgFRXowCfhbKZ71d16sNuKXtwBEsp2DtdNw==}
+ peerDependencies:
+ expo: '*'
+ react: '*'
+
resolution: {integrity: sha512-vizLO4SgnMEL+PPs2dXr+etEOuksjue7yUQBCtfCEdqoDkQlB0r35zI7rS34Wt53sxKWSlM2p+038qQEpxtiFw==}
peerDependencies:
@@ -9303,6 +9315,9 @@ packages:
resolution: {integrity: sha512-KZxYo1BUkWD2TVFLr0MQoM8vUUigWD3LlD83a/75BqC+4qE0Hb1Vo5v1FgcfaNXvfXzr+5EhQ6ing/CaBijTlw==}
engines: {node: '>= 18'}
+ resolution: {integrity: sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==}
+
resolution: {integrity: sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==}
@@ -10171,6 +10186,17 @@ packages:
resolution: {integrity: sha512-FS+XFBNvn3GTAWq26joslQgWNoFu08F4kl0J4CgdNKADkdSGXQyTCnKteIAJy96Br6YbpEU1LSzV5dYtjMkMDg==}
engines: {node: '>=0.10.0'}
+ resolution: {integrity: sha512-caI6ZWpfV/gNeCBhm6alxuCpOxYEFxg9FsgVaOXJWZeKjK2egjxkXcUEFWeS3b9mC6Kwi7Wuu79zfeGtkbdAYw==}
+
+ resolution: {integrity: sha512-39ZNLfxxV7WEOszekIRg56F6VFZrQk7+Lei+8MccNESX3VbQzs1uex/GNesxk6CMTS6ytwqYIBAgLyc9WX/PaA==}
+
+ resolution: {integrity: sha512-Nyb/w7tRQICtfvjAJSN6Q/3aRO8L6eTfEcWpDR/atUyoINkyzducMx6yXA+sz1mazxivY16N3VPkmQ1XohQAcg==}
+ peerDependencies:
+ react-native: '>=0.40.0'
+
resolution: {integrity: sha512-VIMnQi/Z4HT2Fxuwg5KrY174U1VdUIASQVWXXyqtNRtxSr9IYkn1rsI6Tb6HsrHCmB7gVpNwX6JxPTHcH6IoTA==}
engines: {node: '>=6'}
@@ -13692,7 +13718,7 @@ snapshots:
nanostores: 1.0.1
zod: 4.1.12
dependencies:
'@better-fetch/fetch': 1.1.18
@@ -13702,9 +13728,10 @@ snapshots:
optionalDependencies:
+ expo-network: 8.0.8([email protected])([email protected])
dependencies:
'@better-fetch/fetch': 1.1.18
@@ -13714,6 +13741,7 @@ snapshots:
optionalDependencies:
+ expo-network: 8.0.8([email protected])([email protected])
@@ -20405,7 +20433,7 @@ snapshots:
transitivePeerDependencies:
- supports-color
dependencies:
@@ -20462,6 +20490,11 @@ snapshots:
react: 19.1.0
react-native: 0.81.5(@babel/[email protected])(@react-native-community/[email protected]([email protected]))(@types/[email protected])([email protected])
+ dependencies:
+ react: 19.1.0
+
[email protected](49a2902d0574a0052a669c80d9729e84):
dependencies:
@@ -23121,6 +23154,8 @@ snapshots:
dependencies:
minipass: 7.1.2
+
@@ -24053,6 +24088,18 @@ snapshots:
+ dependencies:
+ reactotron-core-contract: 0.3.2
+
+
+ dependencies:
+ mitt: 3.0.1
+ react-native: 0.81.5(@babel/[email protected])(@react-native-community/[email protected]([email protected]))(@types/[email protected])([email protected])
+ reactotron-core-client: 2.9.9
+
dependencies:
graceful-fs: 4.2.11