upload_image.js 852 B

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