UploadApi.ts 750 B

1234567891011121314151617181920212223242526272829
  1. import MessageType from "../utils/MessageType";
  2. import FetchRequest from '@/api/FetchRequest';
  3. import Auth from '@/api/Auth';
  4. import VimConfig from "@/config/VimConfig";
  5. const upload = (tempFilePath : string) => {
  6. return new Promise((resolve, reject) => {
  7. uni.uploadFile({
  8. url: `${FetchRequest.getHost()}/${VimConfig.uploadType}/upload`, //仅为示例,非真实的接口地址
  9. filePath: tempFilePath,
  10. name: 'file',
  11. header: {
  12. "Access-Control-Allow-Origin": "*",
  13. "Authorization": `Bearer ${Auth.getToken()}`,
  14. },
  15. formData: {
  16. 'type': MessageType.voice
  17. },
  18. success: (res) => {
  19. const data = JSON.parse(res.data)
  20. resolve(data)
  21. },
  22. fail: (err) => {
  23. reject(err)
  24. }
  25. })
  26. })
  27. }
  28. export default upload