upload_image.js 704 B

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