在我的后端Node.js代码中,我正在使用Axios TypeScript代码上传文档。但是我在使用表单数据时遇到了一个问题。有人能帮我一下吗?从Axios documentation:
// `data` is the data to be sent as the request body
// Only applicable for request methods 'PUT', 'POST', and 'PATCH'
// When no `transformRequest` is set, must be of one of the following types:
// - string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams
// - Browser only: FormData, File, Blob
// - Node only: Stream, Buffer
[当我尝试使用FormData
时,出现此错误ReferenceError: FormData is not defined
。因此,不确定如何在TypeScript中使用表单数据并将其传递给Axios。
我不能使用来自Node.js的表单数据吗?
我不知道您现在的状况,因为您没有提供任何示例,但是我会与您共享一段代码,希望对您有所帮助
const data = new FormData();
data.append('filename', fileData);
axios.post(url, data);
希望有帮助。
这是我的代码,我如何将一些图像发送到后端。在后端,我使用带有multer的node.js
let formData = new FormData();
formData.append("image", someImage);
axios({
method: "post",
url: "/api/upload/post",
data: formData,
headers: {
"Content-Type": "multipart/form-data"
}
})