宜轩到家/服务到家第三版,换个颜色
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.6 KiB

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
  1. import OSS from "ali-oss"
  2. import { v4 as uuidv4 } from 'uuid';
  3. function uploadFileToOSS(file) {
  4. uni.showLoading({
  5. title: '图片上传中...'
  6. });
  7. return new Promise((resolve,reject) => {
  8. // 创建OSS实例
  9. const client = new OSS({
  10. // region: 'oss-cn-shenzhen',
  11. // accessKeyId: 'LTAI5tMan18fjJPUtr3Aim2W',
  12. // accessKeySecret: 'lhALqqgYijc115wY8c1KfTYkbSnq5I',
  13. // bucket: 'mangoimageapplet',
  14. // endpoint:'oss-cn-shenzhen.aliyuncs.com'
  15. //桶的地址
  16. // region: 'oss-cn-hangzhou',
  17. // //id
  18. // accessKeyId:'LTAI5tDL3dP95KCoepUtqRZX',
  19. // //密钥
  20. // accessKeySecret:'WHUemsg4V9xyZUWRU9WvqwJjTcwe2u',
  21. // //桶的名字
  22. // bucket: 'daohomeimage',
  23. // endpoint:'oss-cn-hangzhou.aliyuncs.com',
  24. //桶的地址
  25. region: 'oss-cn-guangzhou',
  26. //id
  27. accessKeyId:'LTAI5tNycA46YTwm383dRvMV',
  28. //密钥
  29. accessKeySecret:'tAdbYQCmdur6jbZ8hjvgB7T1Z52mIG',
  30. //桶的名字
  31. bucket: 'zhuoqiu-image',
  32. endpoint:'oss-cn-guangzhou.aliyuncs.com',
  33. });
  34. // 设置文件名和文件目录
  35. const suffix = '.' + file.name.split('.').pop();
  36. const fileName = uuidv4() + suffix; // 注意:文件名需要是唯一的
  37. // 使用put接口上传文件
  38. client.multipartUpload(fileName, file, {
  39. headers: {
  40. 'Content-Disposition': 'inline',
  41. 'Content-Type': file.type
  42. }
  43. }).then(res => {
  44. uni.hideLoading();
  45. // resolve('https://image.yixuandaojia.com/' + res.name);
  46. resolve('https://tennis-oss.xzaiyp.top/' + res.name);
  47. }).catch(err => {
  48. uni.hideLoading();
  49. reject(err)
  50. })
  51. })
  52. }
  53. export default uploadFileToOSS