uploadinmage.js 939 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. Page({
  5. data: {
  6. },
  7. onLoad: function () {
  8. wx.hideShareMenu();
  9. var that = this;
  10. that.setData({
  11. Containnerheight: main.getWindowHeight(),
  12. });
  13. },
  14. upload:function(){
  15. wx.chooseImage({
  16. count: 1,
  17. sizeType: ['original', 'compressed'],
  18. sourceType: ['album', 'camera'],
  19. success(res) {
  20. // tempFilePath可以作为img标签的src属性显示图片
  21. const tempFilePaths = res.tempFilePaths;
  22. var url = common.Encrypt("MiaoguoUploadFile");
  23. wx.uploadFile({
  24. url: app.globalData.serverUrlLocalhost +url, // 仅为示例,非真实的接口地址
  25. filePath: tempFilePaths[0],
  26. name: 'file',
  27. formData: {
  28. filename: 'test'
  29. },
  30. success(res) {
  31. }
  32. })
  33. }
  34. });
  35. },
  36. });