upload_image.js 757 B

1234567891011121314151617181920212223242526272829303132
  1. const _my = require("../../__antmove/api/index.js")(my);
  2. const wx = _my;
  3. const { baseUrl } = require("../../utils/func/request"); //单图片上传 file为上传文件暂存地址对象
  4. const api = "/upload/pictureLocal";
  5. const upload_image = (file, type) => {
  6. return new Promise(reslove => {
  7. wx.uploadFile({
  8. url: baseUrl + api,
  9. filePath: type == 1 ? file : file.url.path,
  10. name: "file",
  11. success(res) {
  12. reslove({
  13. // ...file,
  14. url: JSON.parse(res.data).data
  15. });
  16. },
  17. fail(err) {
  18. console.log(err);
  19. wx.showToast({
  20. title: "上传没有成功哦,再试一次吧~",
  21. icon: "error"
  22. });
  23. }
  24. });
  25. });
  26. };
  27. module.exports = upload_image;