Files
zhxg_app_v1.0/plugins/upload.js
2025-07-16 15:34:34 +08:00

24 lines
696 B
JavaScript
Raw Permalink 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 {
baseUrl
} from "@/config.js";
function uploadFile(url, filePath, formData) {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: baseUrl + url, // 上传路径拼接 BASE_URL
filePath: filePath, // 要上传文件资源的路径
name: "file", // 文件对应的 key开发者在服务端可以通过这个 key 获取文件的二进制内容
formData: formData,
header: {
Authorization: "Bearer " + uni.getStorageSync("App-Token")
},
success: (res) => {
resolve(res.data); // 成功回调返回服务器返回的数据
},
fail: (err) => {
reject(err); // 失败回调返回错误信息
}
});
});
}
export default uploadFile;