upload_image.js 615 B

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