Skip to content

TagSpaces is an offline, open source, document manager with tagging support

fix: adding files from device on ios

Ilian Sapundshiev13eb71584758
diff --git a/src/renderer/components/menus/DirectoryMenu.tsx b/src/renderer/components/menus/DirectoryMenu.tsx
index f32a1d877..736ea15d2 100644
--- a/src/renderer/components/menus/DirectoryMenu.tsx
+++ b/src/renderer/components/menus/DirectoryMenu.tsx
@@ -18,7 +18,6 @@
import React, { useContext } from 'react';
import { Menu } from '@mui/material';
-import { formatDateTime4Tag } from '@tagspaces/tagspaces-common/misc';
import AppConfig from '-/AppConfig';
import {
extractParentDirectoryPath,
@@ -260,85 +259,6 @@ function DirectoryMenu(props: Props) {
openImportMacTagDialog(directoryPath);
}
- function onFail(message) {
- console.log('Camera Failed: ' + message);
- }
-
- function onCameraSuccess(imageURL) {
- window.resolveLocalFileSystemURL(
- imageURL,
- (fp) => {
- moveFile(fp.nativeURL);
- },
- () => {
- console.log('Failed to get filesystem url');
- },
- );
- }
-
- function moveFile(filePath) {
- const fileName =
- 'IMG_TS' +
- AppConfig.beginTagContainer +
- formatDateTime4Tag(new Date(), true) +
- AppConfig.endTagContainer +
- '.jpg';
- const newFilePath =
- normalizePath(directoryPath) +
- currentLocation.getDirSeparator() +
- fileName;
-
- renameFilePromise(
- filePath,
- newFilePath,
- currentLocation.uuid,
- undefined,
- false,
- )
- .then((newEntry) => {
- setReflectActions({
- action: 'add',
- entry: newEntry,
- });
- showNotification(
- t('core:fileImportedSuccess', { path: newFilePath }),
- 'default',
- true,
- );
- return true;
- })
- .catch((error) => {
- // TODO showAlertDialog("Saving " + filePath + " failed.");
- console.log('Save to file ' + newFilePath + ' failed ' + error);
- showNotification(
- t('core:fileImportFailed', { path: newFilePath }),
- 'error',
- true,
- );
- return true;
- });
- }
-
- // function loadImageLocal() {
- // onClose();
- // navigator.camera.getPicture(onCameraSuccess, onFail, {
- // destinationType: Camera.DestinationType.FILE_URI,
- // sourceType: Camera.PictureSourceType.PHOTOLIBRARY
- // });
- // }
-
- function cameraTakePicture() {
- // @ts-ignore
- navigator.camera.getPicture(onCameraSuccess, onFail, {
- // quality: 50,
- // @ts-ignore
- destinationType: Camera.DestinationType.FILE_URI, // DATA_URL, // Return base64 encoded string
- // encodingType: Camera.EncodingType.JPEG,
- // @ts-ignore
- mediaType: Camera.MediaType.PICTURE, // ALLMEDIA
- });
- }
-
function setFolderThumbnail() {
const parentDirectoryPath = extractParentDirectoryPath(
directoryPath,
@@ -440,7 +360,7 @@ function DirectoryMenu(props: Props) {
importMacTags,
switchPerspectives ? perspectiveSwitch : undefined,
showProperties,
- cameraTakePicture,
+ undefined, // cameraTakePicture removed — was using Cordova-only navigator.camera API
openAddRemoveTagsDialog,
openInNewWindow,
changeFolderThumbnail,
diff --git a/src/renderer/hooks/IOActionsContextProvider.tsx b/src/renderer/hooks/IOActionsContextProvider.tsx
index 43c80b6be..32f043ee6 100644
--- a/src/renderer/hooks/IOActionsContextProvider.tsx
+++ b/src/renderer/hooks/IOActionsContextProvider.tsx
@@ -1087,11 +1087,15 @@ export const IOActionsContextProvider = ({
onUploadProgress({ key: key, loaded: 0, total: 0 }, undefined);
}
}
- if (
- AppConfig.isElectron ||
- AppConfig.isCordovaiOS ||
- AppConfig.isCapacitoriOS
- ) {
+ // Path-based upload only works where the platform attaches a real native
+ // path to each browser File object: Electron sets it via
+ // `ipcRenderer.getPathForFile`, and the Cordova file plugin populates it.
+ // Capacitor's `<input type="file">` returns standard browser File objects
+ // with `file.path === undefined`, so it must take the FileReader →
+ // ArrayBuffer → saveBinaryFilePromise path below (which uses Uint8Array
+ // — make sure `blobToBase64` in io-capacitor.ts handles ArrayBuffer.isView,
+ // otherwise the writes silently produce garbage).
+ if (AppConfig.isElectron || AppConfig.isCordovaiOS) {
return uploadFiles(
files.map((f) => f.path),
targetPath,
diff --git a/src/renderer/perspectives/common/DirectoryMenuItems.tsx b/src/renderer/perspectives/common/DirectoryMenuItems.tsx
index 77eb5805b..2c2ee1952 100644
--- a/src/renderer/perspectives/common/DirectoryMenuItems.tsx
+++ b/src/renderer/perspectives/common/DirectoryMenuItems.tsx
@@ -528,24 +528,6 @@ export function getDirectoryMenuItems(
);
}
- if (AppConfig.isNativeMobile && cameraTakePicture) {
- menuItems.push(
- <MenuItem
- key="takePicture"
- data-tid="takePicture"
- onClick={() => {
- onClose();
- cameraTakePicture();
- }}
- >
- <ListItemIcon>
- <AddExistingFileIcon />
- </ListItemIcon>
- <ListItemText primary={t('core:cameraTakePicture')} />
- </MenuItem>,
- );
- }
-
if (selectedEntries.length < 2 && showProperties) {
menuItems.push(<Divider key={`divider-${menuItems.length}`} />);
menuItems.push(