帧视界壹通告,付费看视频的微信小程序
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.

38 lines
828 B

11 months ago
  1. import OSS from "ali-oss"
  2. import utils from './utils.js'
  3. import config from '../config.js'
  4. function uploadFileToOSS(file) {
  5. uni.showLoading({
  6. title: '上传中...'
  7. });
  8. return new Promise((resolve,reject) => {
  9. // 创建OSS实例
  10. const client = new OSS(config.aliOss.config);
  11. // 设置文件名和文件目录
  12. const suffix = '.' + file.name.split('.').pop();
  13. const fileName = utils.generateUUID() + suffix; // 注意:文件名需要是唯一的
  14. // 使用put接口上传文件
  15. client.multipartUpload(fileName, file, {
  16. headers: {
  17. 'Content-Disposition': 'inline',
  18. 'Content-Type': file.type
  19. }
  20. }).then(res => {
  21. uni.hideLoading();
  22. resolve(config.aliOss.url + res.name);
  23. }).catch(err => {
  24. uni.hideLoading();
  25. reject(err)
  26. })
  27. })
  28. }
  29. export default uploadFileToOSS