wx-chant/api/upload.js
2025-11-05 22:15:27 +08:00

29 lines
910 B
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.

function uploadFile(filePath) {
return new Promise((resolve, reject) => {
if (!filePath) {
const err = new Error('uploadFile requires a filePath parameter');
console.error('上传失败:未提供文件路径', err);
return reject(err);
}
wx.uploadFile({
filePath: filePath, // 图片临时文件路径(由调用方传入)
name: 'file', // 服务器接收文件的字段名,需与后端对应
url: 'https://mini-chat.1024tool.vip/api/admin/upload/image', // 服务器接收图片的接口地址
success: (res) => {
resolve(res);
},
fail: (err) => {
console.error('上传失败', err);
reject(err);
}
});
})
}
// 导出请求和服务地址CommonJS 兼容)
module.exports = uploadFile;