kinit/kinit-uni/common/utils/postFile.js
2022-12-04 21:42:59 +08:00

40 lines
883 B
Python
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.

/**
uniapp 上传文件到后台接口
官方文档https://uniapp.dcloud.io/api/request/network-file.html#uploadfile
博客https://www.jianshu.com/p/71ad2f45120c
*/
import { API_BASE_URL } from '@/common/setting/index'
import { getToken, removeToken, getStorage } from '@/common/utils/cookies'
// 单个文件上传
export function uploadFile(api, file, data={}) {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: API_BASE_URL + api,
filePath: file,
name: 'file',
timeout: 60000,
formData: data,
header: {
ossign: getStorage("ossign"),
Authorization: getToken()
},
success: (res) => {
let data = JSON.parse(res.data);
if (data.code !== 200) {
reject(data);
}
resolve(data);
},
fail: (err) => {
console.log("上传失败", err);
reject(err);
}
});
})
}