Use custom base 64 <> blob function
This commit is contained in:
parent
f675cc4fee
commit
f74ef19180
@ -18,7 +18,7 @@ export const convertUploadToPhoto = async (
|
||||
console.log('Fetching original file');
|
||||
const fileBytes = await fetch(urlOrigin, { cache: 'no-store' })
|
||||
.then(res => res.arrayBuffer());
|
||||
const fileWithoutGps = await stripGpsFromFile(fileBytes);
|
||||
const fileWithoutGps = stripGpsFromFile(fileBytes);
|
||||
console.log('Uploading file without GPS');
|
||||
return putFile(fileWithoutGps, photoPath).then(async url => {
|
||||
if (url) {
|
||||
|
||||
14
src/utility/data.ts
Normal file
14
src/utility/data.ts
Normal file
@ -0,0 +1,14 @@
|
||||
export const b64toBlob = (
|
||||
data: string,
|
||||
type: string = 'image/jpeg',
|
||||
): Blob => {
|
||||
const byteString = atob(data.split(',')[1]);
|
||||
const ab = new ArrayBuffer(byteString.length);
|
||||
const ia = new Uint8Array(ab);
|
||||
|
||||
for (let i = 0; i < byteString.length; i++) {
|
||||
ia[i] = byteString.charCodeAt(i);
|
||||
}
|
||||
|
||||
return new Blob([ab], { type });
|
||||
};
|
||||
@ -1,8 +1,9 @@
|
||||
import * as PiExif from 'piexifjs';
|
||||
import { b64toBlob } from './data';
|
||||
|
||||
export const stripGpsFromFile = async (
|
||||
export const stripGpsFromFile = (
|
||||
fileBytes: ArrayBuffer
|
||||
): Promise<Blob> => {
|
||||
): Blob => {
|
||||
const base64 = Buffer.from(fileBytes).toString('base64');
|
||||
const base64Url = `data:image/jpeg;base64,${base64}`;
|
||||
|
||||
@ -17,5 +18,7 @@ export const stripGpsFromFile = async (
|
||||
base64Url,
|
||||
);
|
||||
|
||||
return fetch(data, { cache: 'no-store' }).then(res => res.blob());
|
||||
console.log('EXIF updated');
|
||||
|
||||
return b64toBlob(data);
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user