调用uni.uploadFile
- 发布:2024-06-14 20:17
- 更新:2024-06-14 21:35
- 阅读:245
产品分类: uniapp/小程序/微信
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win11
HBuilderX类型: 正式
HBuilderX版本号: 4.15
第三方开发者工具版本号: 1.06.2402040win32-x64
基础库版本号: 3.4.6
项目创建方式: HBuilderX
操作步骤:
预期结果:
Status Code:200
Status Code:200
实际结果:
Status Code:400
Status Code:400
bug描述:
uni.uploadFile上传图片Status Code经常报400
cookies: []
data: "<!doctype html><html lang="en"><head><title>HTTP Status 400 – Bad Request</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 400 – Bad Request</h1></body></html>"
errMsg: "uploadFile:ok"
header: {Content-Type: "text/html;charset=utf-8", Content-Language: "en", Content-Length: "435", Date: "Fri, 14 Jun 2024 12:12:39 GMT", Connection: "close"}
statusCode: 400
uploadFileUrl: (params) => {
return new Promise((resolve, reject) => {
const { file, formData = {}, header = {} } = params
console.log(file)
uni.uploadFile({
url: `${import.meta.env.VITE_APP_BASE_API}/p/file/upload`,
filePath: file,
name: "file",
formData,
header,
success: function (res) {
let data = res.data;
resolve(JSON.parse(data));
},
fail: function (err) {
uni.showToast({
title: err.msg || "图片上传失败",
icon: "none",
});
reject(err);
},
complete: function (err) {
console.log(err)
}
});
});
},
1 个回复
喜欢技术的前端 - QQ---445849201
可以把接口在postman 之类的工具上多试试,uni.uploadFile 用了好多年了,一般不会出问题