Connected picture state to redux
This commit is contained in:
1 parent
223dd280d4
commit
7f57f9fa0c
3 files changed
+88
-44
No files matched your search
@@ -1,13 +1,3 @@
|
||||
import { useMemo } from "react";
|
||||
|
||||
export const bytesToUrl = (bytes) => {
|
||||
return useMemo(() => {
|
||||
const blob = new Blob([bytes], { type: "image/jpeg" });
|
||||
const url = URL.createObjectURL(blob);
|
||||
return url;
|
||||
}, [bytes]);
|
||||
};
|
||||
|
||||
export const formatBytes = (bytes) => {
|
||||
if (bytes === 0) return "0 Bytes";
|
||||
const megabytes = bytes / (1024 * 1024);
|
||||
@@ -17,5 +7,19 @@ export const formatBytes = (bytes) => {
|
||||
export const checkImage = (url) => {
|
||||
const img = new Image();
|
||||
img.src = url;
|
||||
return img.naturalWidth !==0;
|
||||
}
|
||||
return img.naturalWidth !== 0;
|
||||
};
|
||||
|
||||
export const bufferTo64 = (bufferData) => {
|
||||
const uint8Array = new Uint8Array(bufferData.data);
|
||||
const blob = new Blob([uint8Array], { type: bufferData.contentType });
|
||||
return new Promise((resolve) => {
|
||||
const reader = new FileReader();
|
||||
reader.onloadend = () => {
|
||||
resolve(reader.result);
|
||||
};
|
||||
reader.readAsDataURL(blob);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user