Skip to content

Commit

Permalink
fix: offline upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ledouxm committed Nov 12, 2024
1 parent 46c791e commit 73afd33
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions packages/frontend/src/features/upload/UploadImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ export const UploadImage = ({ reportId }: { reportId: string }) => {

const uploadImageMutation = useMutation(async (file: File) => {
const picId = v4();
const buffer = await getArrayBufferFromBlob(file);

console.log("oui");

await db.tmp_pictures.create({ data: { id: picId, reportId, createdAt: new Date() } });
await set(picId, buffer, getPicturesStore());

try {
const formData = new FormData();
const buffer = await getArrayBufferFromBlob(file);

formData.append("file", new Blob([buffer]), "file");
formData.append("reportId", reportId);
Expand All @@ -43,14 +48,7 @@ export const UploadImage = ({ reportId }: { reportId: string }) => {
query: { reportId: reportId, id: picId },
} as any);
} catch {
const picturesStore = getPicturesStore();
const toUploadStore = getToUploadStore();

const buffer = await getArrayBufferFromBlob(file);
await set(picId, buffer, picturesStore);
await set(picId, reportId, toUploadStore);

await db.tmp_pictures.create({ data: { id: picId, reportId, createdAt: new Date() } });
await set(picId, reportId, getToUploadStore());
syncImages();
}
});
Expand Down

0 comments on commit 73afd33

Please sign in to comment.