upload_image.js 953 B

123456789101112131415161718192021222324252627282930313233
  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. // console.log(file);
  8. return new Promise(reslove => {
  9. // console.log(baseUrl + api)
  10. wx.uploadFile({
  11. url: baseUrl + api,
  12. filePath: file.url,
  13. name: "file",
  14. success(res) {
  15. reslove({
  16. ...file,
  17. url: JSON.parse(res.data).data
  18. });
  19. // console.log(res)
  20. },
  21. fail(err) {
  22. console.log(err);
  23. wx.showToast({
  24. title: "上传没有成功哦,再试一次吧~",
  25. icon: "error"
  26. });
  27. }
  28. });
  29. });
  30. };
  31. module.exports = upload_image;