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,22 +85,43 @@ 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);
reader.addEventListener(
'load',
async () => {
// this will then display a text gpxfile
const tags = ExifReader.load(reader.result);
console.log({
caller: 'ImportSingleFile / Jpeg',
file,
type: file.type,
result: reader.result,
tags,
});
//parseGpx(reader.result);
},
false
);
} else {
reader.readAsText(file);
reader.addEventListener(
'load', 'load',
async () => { async () => {
// this will then display a text gpxfile // this will then display a text gpxfile
console.log({ console.log({
caller: 'ImportSingleFile / XML', caller: 'ImportSingleFile / XML',
gpxFile: file, file,
result: gpxReader.result, type: file.type,
result: reader.result,
}); });
parseGpx(gpxReader.result); parseGpx(reader.result);
}, },
false false
); );
} }
}
const doImport = async () => { const doImport = async () => {
setState('importing'); setState('importing');
// console.log({ caller: 'GpxImport / JSON', file, gpx }); // console.log({ caller: 'GpxImport / JSON', file, gpx });