上传插件,不包含上传的前端实现,只提供后端接口等,其他地方接入插件上传。包括上传进度、断点续传等

index.ts 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { getFilemd5sum, getBase64 } from './utils.js'
  2. interface upload_sdk {
  3. //初始化文件 md5
  4. generateMd5: (file: File) => any
  5. //初始化图片 base64
  6. generateBase64: (file: File) =>any
  7. //上传
  8. action: () => Promise<any>
  9. //成功返回函数
  10. onSuccess: () => string
  11. //续传
  12. onContinue: () => number
  13. //错误
  14. onError: () => number
  15. }
  16. class UploadSdk implements upload_sdk {
  17. private host: string
  18. private origin: string
  19. private token: string
  20. private file: File
  21. private md5: any
  22. private base64: any
  23. constructor(host: string, origin: string, token: string, file: File){
  24. this.host = host
  25. this.origin = origin
  26. this.token = token
  27. this.file = file
  28. }
  29. generateMd5 = async (file: File) => {
  30. let md5 = await getFilemd5sum(file)
  31. return md5
  32. }
  33. generateBase64 = async (file: File) => {
  34. let base64 = await getBase64(file)
  35. return base64
  36. }
  37. //上传
  38. action = async () => {
  39. return new Promise((resolve, reject) => {
  40. resolve()
  41. })
  42. }
  43. //成功返回函数
  44. onSuccess = () => {
  45. return 'success'
  46. }
  47. //续传
  48. onContinue = () => {
  49. return 90
  50. }
  51. //错误
  52. onError = () => {
  53. return 200
  54. }
  55. }