import useGizoneConfig from '../utils/useGizoneConfig';
import useAccessToken from '../auth/useAccessToken';
// 上传文件并保留文件名
export function useUploadKeepName() {
const gizoneConfig = useGizoneConfig();
const token = useAccessToken();
const url = `${gizoneConfig.apiBaseUrl}/operation/file/uploadKeepName`;
return (name: string, filePath: string) => {
return new Promise<string>((resolve, reject) => {
// @ts-ignore
uni.uploadFile({
url,
name,
filePath,
header: {
Authorization: `Bearer ${token.value}`,
},
// @ts-ignore
success: res => {
resolve(JSON.parse(res.data)?.data.fileUrl);
},
// @ts-ignore
fail: err => {
reject(err);
}
})
})
}
}
使用
const uploadKeepName = useUploadKeepName();
uploadKeepName (‘file’, url)