12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import { getFilemd5sum, getBase64 } from './utils.js'
-
- interface upload_sdk {
-
- //初始化文件 md5
- generateMd5: (file: File) => any
- //初始化图片 base64
- generateBase64: (file: File) =>any
- //上传
- action: () => Promise<any>
- //成功返回函数
- onSuccess: () => string
- //续传
- onContinue: () => number
- //错误
- onError: () => number
-
- }
-
- class UploadSdk implements upload_sdk {
-
- private host: string
- private origin: string
- private token: string
- private file: File
- private md5: any
- private base64: any
-
-
- constructor(host: string, origin: string, token: string, file: File){
- this.host = host
- this.origin = origin
- this.token = token
- this.file = file
- }
-
- generateMd5 = async (file: File) => {
- let md5 = await getFilemd5sum(file)
- return md5
- }
-
- generateBase64 = async (file: File) => {
- let base64 = await getBase64(file)
- return base64
- }
- //上传
- action = async () => {
- return new Promise((resolve, reject) => {
- resolve()
- })
- }
- //成功返回函数
- onSuccess = () => {
- return 'success'
- }
- //续传
- onContinue = () => {
- return 90
- }
- //错误
- onError = () => {
- return 200
- }
-
- }
-
-
-
-
-
-
-
|