diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/hooks/useS3Preupload.tsx | 14 | ||||
-rw-r--r-- | src/utils/files.ts | 14 |
2 files changed, 15 insertions, 13 deletions
diff --git a/src/hooks/useS3Preupload.tsx b/src/hooks/useS3Preupload.tsx index 651bfb6..9516459 100644 --- a/src/hooks/useS3Preupload.tsx +++ b/src/hooks/useS3Preupload.tsx @@ -1,9 +1,8 @@ import { useState, useCallback, useMemo } from 'react'; import axios from 'axios'; import Bluebird from 'bluebird'; -import Compressor from 'compressorjs'; import { get } from '../requests'; - +import { compressFile } from '../utils/files'; interface ProgressEvent { loaded: number; @@ -17,17 +16,6 @@ interface Hook { progress: number; } - -const compressFile = (file: File, quality = 0.6): Promise<Blob> => { - return new Promise((resolve, reject) => { - return new Compressor(file, { - success: result => resolve(result), - error: err => reject(err), - quality - }); - }); -}; - export default (): Hook => { const [url, setUrl] = useState<string>(); const [file, setFile] = useState<File>(); diff --git a/src/utils/files.ts b/src/utils/files.ts index 98c342c..5d16fdb 100644 --- a/src/utils/files.ts +++ b/src/utils/files.ts @@ -1,3 +1,6 @@ +import Compressor from 'compressorjs'; + + export const getLocalFileUrl = (file: File): Promise<string> => { return new Promise((resolve, reject) => { const reader = new FileReader(); @@ -13,3 +16,14 @@ export const getLocalFileUrl = (file: File): Promise<string> => { if (file) reader.readAsDataURL(file); }); }; + +export const compressFile = (file: File, quality = 0.6): Promise<Blob> => { + return new Promise((resolve, reject) => { + return new Compressor(file, { + success: result => resolve(result), + error: err => reject(err), + quality + }); + }); +}; + |