12345678910111213141516171819202122232425262728293031 |
- import {wxToPromise} from "./wx";
- import config from "../model/config";
- import Http from "./http";
- class FileUploader extends Http {
- static async upload(filePath, key = 'file') {
- let res
- try {
- res = await wxToPromise('uploadFile', {
- url: `${config.API}/v1/file`,
- filePath: filePath,
- name: key,
- })
- } catch (e) {
- console.log(e)
- FileUploader._showError(-100)
- throw new Error(e.errMsg)
- }
- const serverData = JSON.parse(res.data)
- if (res.statusCode !== 201) {
- FileUploader._showError(serverData.code, serverData.msg)
- throw new Error(serverData.msg)
- }
- return serverData.data
- }
- }
- export default FileUploader
|