Skip to content

Commit

Permalink
test1
Browse files Browse the repository at this point in the history
  • Loading branch information
burtonjong committed Aug 5, 2024
1 parent 6a4e74d commit 593de7b
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/components/user/User.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,26 @@ export default function UserProfile() {
},
});

const imagePath = `public/${data?.id}/profile.png`;
const imagePath = `public/${data?.firstName}${data?.lastName}/profile.png`;

const imageUploadPath = `public/${data?.firstName}${data?.lastName}/profile.png`;
const imageUploadPath = `public/${data?.firstName}${data?.lastName}/`;

const processFile = async ({ file }: { file: File }) => {
const fileExtension = file.name.split(".").pop();

return file
.arrayBuffer()
.then((filebuffer: BufferSource) =>
window.crypto.subtle.digest("SHA-1", filebuffer),
)
.then((hashBuffer) => {
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashHex = hashArray
.map((a) => a.toString(16).padStart(2, "0"))
.join("");
return { file, key: `${hashHex}.${fileExtension}` };
});
};

return (
<div className="flex flex-col items-center justify-center gap-4">
Expand Down Expand Up @@ -65,6 +82,7 @@ export default function UserProfile() {
acceptedFileTypes={["image/*"]}
path={imageUploadPath}
maxFileCount={1}
processFile={processFile}
isResumable
autoUpload={false}
/>
Expand Down

0 comments on commit 593de7b

Please sign in to comment.