first save
This commit is contained in:
34
scoring/utils/fileUtils.js
Normal file
34
scoring/utils/fileUtils.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import { BASE_URL } from "./CommonValues";
|
||||
export async function uploadFile(filePath) {
|
||||
console.log("文件路径", filePath)
|
||||
if(!filePath) {
|
||||
uni.showToast({
|
||||
title: '未选择文件',
|
||||
icon: 'error'
|
||||
})
|
||||
return;
|
||||
}
|
||||
const res = await uni.uploadFile({
|
||||
url: BASE_URL + "/txy/oss/upload", // 请求的服务器URL
|
||||
filePath: filePath, // 要上传文件资源的路径
|
||||
name: "file" // 必须填,是服务器端约定的字段名
|
||||
});
|
||||
console.log("上传文件结果1", res)
|
||||
if(res.statusCode != 200) {
|
||||
uni.showToast({
|
||||
title: '文件上传失败:system',
|
||||
icon: 'error'
|
||||
})
|
||||
return;
|
||||
}
|
||||
const resData = JSON.parse(res.data);
|
||||
if(resData.statusCode != 200) {
|
||||
uni.showToast({
|
||||
title: '文件上传失败:code',
|
||||
icon: 'error'
|
||||
})
|
||||
return;
|
||||
}
|
||||
console.log("上传文件结果", resData)
|
||||
return resData.data
|
||||
}
|
||||
Reference in New Issue
Block a user