gpt4 book ai didi

jquery - 使用 jQuery 通过表单数据上传文件时出错

转载 作者:行者123 更新时间:2023-12-01 05:11:39 27 4
gpt4 key购买 nike

我在使用 jQuery 通过 Formdata 上传文件时遇到错误。

Error details - Required request body is missing. The input message is not readable.

Error Screenshot

  1. 为什么边界值不同?
  2. 为什么服务失败?我的表单数据有问题吗?请与成功截图进行对比。

Successful call

var formData = new FormData();
formData.append('object', JSON.stringify({
"properties": {
"object_name": "Test Doc4",
"r_object_type": "eri_wg_doc",
"eri_document_type": "Agenda",
"eri_conf_class": "Ericsson Confidential",
"eri_audience": "Workgroup Members - Restricted",
"ignore-number": false,
"allow-new-version": false
}
}));

formData.append('content', files[0]);

var aData = jQuery.ajax({
type: "POST",
contentType: "multipart/form-data;boundary=----LGZlKL2faC2ilpCJ",
headers: {
"Authorization": "Basic " + btoa("username" + ":" + "password"),
"accept": "application/json"
},
url: "https://domain/repositories/folders/0b004cff89977940/documents?skipSSO=true",
processData: false,
data: formData,
success: function(data, status) {
console.log(data);
}
});

最佳答案

问题的原因是因为您设置了自己的contentType和边界。通过 jQuery AJAX 上传文件时,这不是正确的做法。

正确的做法是在向 data 属性提供 FormData 对象时使用 contentType: false。然后 jQuery 将配置 contentType header 本身,并保持边界一致。

关于jquery - 使用 jQuery 通过表单数据上传文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61455409/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com