Reading exif tags

This commit is contained in:
Eric van der Vlist 2023-04-04 15:25:53 +02:00
parent 854a9d701a
commit f52191966c
1 changed files with 39 additions and 17 deletions

View File

@ -19,6 +19,7 @@ import {
Filesystem as CapacitorFileSystem, Filesystem as CapacitorFileSystem,
Encoding, Encoding,
} from '@capacitor/filesystem'; } from '@capacitor/filesystem';
import ExifReader from 'exifreader';
interface Props { interface Props {
file: File; file: File;
@ -84,21 +85,42 @@ const ImportSingleFile: Component<Props> = ({ file: file }) => {
parseGpx(content.data); parseGpx(content.data);
}); });
} else { } else {
const gpxReader = new FileReader(); const reader = new FileReader();
gpxReader.readAsText(file); if (file.type === 'image/jpeg') {
gpxReader.addEventListener( reader.readAsArrayBuffer(file);
'load', reader.addEventListener(
async () => { 'load',
// this will then display a text gpxfile async () => {
console.log({ // this will then display a text gpxfile
caller: 'ImportSingleFile / XML', const tags = ExifReader.load(reader.result);
gpxFile: file, console.log({
result: gpxReader.result, caller: 'ImportSingleFile / Jpeg',
}); file,
parseGpx(gpxReader.result); type: file.type,
}, result: reader.result,
false tags,
); });
//parseGpx(reader.result);
},
false
);
} else {
reader.readAsText(file);
reader.addEventListener(
'load',
async () => {
// this will then display a text gpxfile
console.log({
caller: 'ImportSingleFile / XML',
file,
type: file.type,
result: reader.result,
});
parseGpx(reader.result);
},
false
);
}
} }
const doImport = async () => { const doImport = async () => {
setState('importing'); setState('importing');
@ -113,9 +135,9 @@ const ImportSingleFile: Component<Props> = ({ file: file }) => {
tech: tech:
typeof file === 'string' typeof file === 'string'
? { ? {
importDate: new Date().toISOString(), importDate: new Date().toISOString(),
uri: file, uri: file,
} }
: { : {
lastModified: new Date(file.lastModified).toISOString(), lastModified: new Date(file.lastModified).toISOString(),
importDate: new Date().toISOString(), importDate: new Date().toISOString(),