replace dataURL so that piexif considers file as JPEG

This commit is contained in:
Abhinav 2021-11-11 11:29:39 +05:30
parent 2636568724
commit f92fa1c331

View file

@ -35,7 +35,10 @@ export async function updateFileModifyDateInEXIF(
updatedDate: Date
) {
const fileURL = URL.createObjectURL(fileBlob);
const imageDataURL = await convertImageToDataURL(fileURL);
let imageDataURL = await convertImageToDataURL(fileURL);
imageDataURL =
'data:image/jpeg;base64' +
imageDataURL.slice(imageDataURL.indexOf(','));
const exifObj = piexif.load(imageDataURL);
if (!exifObj['0th']) {
exifObj['0th'] = {};
@ -49,9 +52,9 @@ export async function updateFileModifyDateInEXIF(
export async function convertImageToDataURL(url: string) {
const blob = await fetch(url).then((r) => r.blob());
const dataUrl = await new Promise((resolve) => {
const dataUrl = await new Promise<string>((resolve) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onload = () => resolve(reader.result as string);
reader.readAsDataURL(blob);
});
return dataUrl;