收藏
回答

wx.uploadFile formData 携带参数失效

框架类型 问题类型 操作系统 工具版本
小程序 Bug Windows 1.05
let data = {
              "type""jpg",
              "spec""1",
              "bk""blue",
              "beauty_degree"1.5
            }
            data.photo = base64Data;

wx.uploadFile({
              url'https://www.pudding233.com/api/data.php'//后端接口
              filePath: tempFilePaths[0],
              method'POST',
              name'file',
              header: {
                "Content-Type""application/json"
              },
              // header: { 'Content-Type': 'multipart/form-data' },
              formDataJSON.stringify(data),
              successfunction (res{
                wx.hideLoading({
                  success(res) => {},
                });
                if (res.statusCode !== 200) {
                  wx.showModal({
                    title'提示',
                    content'上传失败',
                    showCancelfalse
                  });
                  return;
                } else {
                  console.log(res.data);
                  wx.navigateTo({
                    url"../imgDetail/imgDetail?img=" + res.data,
                    events: {},
                    successfunction (res{}
                  })
                }
              },
              fail(e) {
                wx.showModal({
                  title'提示',
                  content'上传失败',
                  showCancelfalse
                });
              },
              complete() {
                wx.hideToast(); //隐藏Toast
              }
            })
回答关注问题邀请回答
收藏

3 个回答

  • 木易之星
    木易之星
    2023-12-15
    不能从formData获取参数,只能要接口地址后面传参
    


    2023-12-15
    有用
    回复
  • 郑钱花
    郑钱花
    2022-04-24

    formData 为什么要字符串?它是个Object啊。不看文档吗

    2022-04-24
    有用
    回复
  • 武曲心
    武曲心
    2022-04-24

    不要设置Content-Type

    2022-04-24
    有用
    回复
登录 后发表内容