Files
aishangjia-uniapp/api/upload.js
2023-08-04 13:14:48 +08:00

56 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}