第一次提交
This commit is contained in:
56
api/upload.js
Normal file
56
api/upload.js
Normal file
@@ -0,0 +1,56 @@
|
||||
import http from './index.js';
|
||||
import {
|
||||
fileUrl
|
||||
} from '@/config.js';
|
||||
import storage from '@/utils/storage'
|
||||
import dayjs from "dayjs"
|
||||
import appConfig from '@/config.js'
|
||||
|
||||
// 文件服务器
|
||||
// export const uploadFile = (file) => http.upload(fileUrl + '/api/file/upload', file)
|
||||
|
||||
// 阿里云OSS
|
||||
export const uploadFile = (file) => http.upload('/oss/upload', file)
|
||||
// export const uploadFile = async ({filePath}) => {
|
||||
|
||||
// // 获取临时凭证
|
||||
// let sts = storage.get('sts');
|
||||
// if(!sts){
|
||||
// const stsRes = await http.get('/oss/getPostForm')
|
||||
// sts = stsRes.data
|
||||
// storage.set('sts', sts, 60)
|
||||
// }
|
||||
// const {polocyBase64,signature} = sts;
|
||||
// var suffix = filePath.substring(filePath.lastIndexOf(".")); //.txt
|
||||
// const fileName = dayjs().format('YYYYMMDD') + '/'+ uni.$u.guid() + suffix;
|
||||
// return new Promise((reso, rej) => {
|
||||
// uni.uploadFile({
|
||||
// url: appConfig.fileUrl, // 开发者服务器的URL。
|
||||
// filePath: filePath,
|
||||
// name: 'file', // 必须填file。
|
||||
// formData: {
|
||||
// key: fileName,
|
||||
// 'policy': polocyBase64,
|
||||
// 'OSSAccessKeyId': 'LTAI5t8UTh8CTXEi2dYxobhj',
|
||||
// 'success_action_status': '200', //让服务端返回200,不然,默认会返回204
|
||||
// 'signature': signature,
|
||||
// // 'x-oss-security-token': this.stsToken,
|
||||
// },
|
||||
// success: (res) => {
|
||||
// const webUrl = appConfig.fileUrl + '/' + fileName;
|
||||
// reso({data: {url: webUrl,thumb: webUrl}})
|
||||
// },
|
||||
// fail: err => {
|
||||
// rej(err)
|
||||
// }
|
||||
// });
|
||||
// })
|
||||
|
||||
|
||||
// }
|
||||
|
||||
export const getTempOssToken = () => http.get('/oss/getTempToken')
|
||||
export default {
|
||||
uploadFile,
|
||||
getTempOssToken
|
||||
}
|
||||
Reference in New Issue
Block a user