apiUpload.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { get, upload } from "./http";
  2. const prefix = 'devicesApi/picture/upload';
  3. const prefixObs = 'devicesApi/picture/obs-upload';
  4. export default {
  5. /**
  6. * 上传图片(已过时)
  7. * @param {*} uri 图片地址
  8. * @param {*} mime 图片类型
  9. * @param {*} type 图片分类 ↓
  10. * USER_PROFILE 用户头像
  11. * FEEDBACK 用户反馈
  12. * SERVICE_LOGO 服务提供商logo
  13. * SITE 站点
  14. * PDVL 驾驶证
  15. * @returns 服务器路径
  16. */
  17. uploadImageOld(uri, mime, type) {
  18. let data = new FormData();
  19. data.append('file', {
  20. uri: uri,
  21. type: mime,
  22. name: getFileName(uri)
  23. });
  24. return upload(prefix, data, {photoSubDir: type});
  25. },
  26. uploadImage(uri, mime, type="") {
  27. let data = new FormData();
  28. data.append('file', {
  29. uri: uri,
  30. type: mime,
  31. name: getFileName(uri)
  32. });
  33. return upload(prefixObs, data, {photoSubDir: type});
  34. },
  35. testNotification() {
  36. return get('devicesApi/googleNotification/doNotification');
  37. }
  38. }
  39. const getFileName = (path) => {
  40. var pos = path.lastIndexOf("/");
  41. var name = path.substring(pos+1);
  42. return name;
  43. }