1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- /**
- * 微信小程序通过STS直传阿里云OSS
- *(uniapp版上传,小程序原生需要将uni.XXX替换为wx.XXX)
- *
- * @param {filePath} 图片临时地址
- * @param {option|Object} OSS和STS配置
- * @param {savePath} oss中的文件目录
- * @param {AccessKeySecret} 服务端返回的STS中的AccessKeySecret
- * @param {SecurityToken} 服务端返回的STS中的SecurityToken
- * @param {AccessKeyId} 服务端返回的STS中的AccessKeyId
- * @param {bucket} 存储桶
- * @param {area} 地区
- * @return {string|boolean} 成功返回文件地址,失败返回false
- */
- import getFileAccessUrl from "@/js_sdk/tencentcloud-plugin-cos/get-file-access-url";
- import tools from "./tools";
- import uploadFile from "@/js_sdk/tencentcloud-plugin-cos/upload-file";
- let cosServe={}
- /**
- * COS文件上传
- * @param file
- * @param folder 上传目录
- * @returns {Promise<unknown>}
- */
- cosServe.txUploadFile=async function (file,folder){
- //默认为个人目录gallery
- tools.showLoading()
- folder=folder==='moment'?'moment':'gallery'
- let user_id= uni.getStorageSync('user_id')
- if(!user_id){
- user_id='00'
- }
- if(!file.name){
- file.name=file.path
- }
- let key=folder+'/'+user_id+'/'+tools.getDate()+'/'+tools.getRandFileName(file.name)
- // #ifdef APP-PLUS
- file =file.path;
- //#endif
- let url = await uploadFile(file,key);
- tools.hideLoading()
- return url
- }
- cosServe.getSignUrl= async function (url){
- if(!url){
- return ''
- }
- console.log(url)
- url= url.replace('https://','')
- url= url.replace('http://','')
- url= url.replace('icoco-1317650740.cos.ap-guangzhou.myqcloud.com/','')
- let signUrl = await getFileAccessUrl(url);
- console.log(signUrl)
- return signUrl
- }
- export default cosServe
|