使用fetch进行formdata 文件上传踩的坑

使用fetch进行formdata 文件上传踩的坑

fetch 进行formdata文件上传时不要乱设置content-type

      let opts = {
    
    
        method: "POST",
        body: formData,
        headers: {
    
    
    		 // Content-Type:'application/x-www-form-urlencoded'不要随便设置
        },
      };

      let url = "http://localhost:3000/upload";
      fetch(url, opts)
        .then((res) => res.text())
        .then((data) => console.log(data));
        

千万不要跟着 百度 “fetch”+“formdata” 关键词第一篇文章里说的那样设置 这篇文章里的内容来做 被坑惨了 /(ㄒoㄒ)/~~

猜你喜欢

转载自blog.csdn.net/anothercx/article/details/111937943