upload_image.js 822 B

123456789101112131415161718192021222324252627282930
  1. const {
  2. baseUrl
  3. } = require("../../utils/func/request");
  4. //单图片上传 file为上传文件暂存地址对象
  5. const api = '/upload/pictureLocal'
  6. const upload_image = (file, type) => {
  7. return new Promise((reslove) => {
  8. wx.uploadFile({
  9. url: baseUrl + api,
  10. filePath: type == 1 ? file : file.url.tempFilePath,
  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