動態

詳情 返回 返回

使用form-data的content-type上傳文件問題 - 動態 詳情

問題

當後端需要我們上傳文件時,一般會用form-data的類型。

接口文檔像這樣:
image.png

目標是發出這樣一個請求:
image.png

代碼示例

// file從input為file的輸入框獲取
const formData = new FormData();
formData.append('code', 'xxx')
formData.append('index', "xxx");
formData.append('file', file); 

fetch('/excel/import', {
  method: 'POST',
  body: formData
});

注意

不要對formdata進行包裝,以下是錯誤示例:

fetch('/excel/import', {
  method: 'POST',
  body: {
      formData
  }
});
user avatar honwhy 頭像 aqiongbei 頭像 yelloxing 頭像 huajianketang 頭像 jiavan 頭像 wmbuke 頭像 weishiledanhe 頭像 yuhuashi_584a46acea21f 頭像 leoych 頭像 DolphinScheduler 頭像 shimiandeshatanku 頭像 huaiyug 頭像
點贊 52 用戶, 點贊了這篇動態!
點贊

Add a new 評論

Some HTML is okay.