我们想将一个图像文件作为multipart/form发送到后端,我们尝试使用html表单来获取文件并将文件作为formData发送,这里是代码
export default class Task extends React.Component {
uploadAction() {
var data = new FormData();
var imagedata = document.querySelector('input[type="file"]').files[0];
data.append("data", imagedata);
fetch("http://localhost:8910/taskCreationController/createStoryTask", {
mode: 'no-cors',
method: "POST",
headers: {
"Content-Type": "multipart/form-data"
"Accept": "application/json",
"type": "formData"
},
body: data
}).then(function (res) {
if (res.ok) {
alert("Perfect! ");
} else if (res.status == 401) {
alert("Oops! ");
}
}, function (e) {
alert("Error submitting form!");
});
}
render() {
return (
<form encType="multipart/form-data" action="">
<input type="file" name="fileName" defaultValue="fileName"></input>
<input type="button" value="upload" onClick={this.uploadAction.bind(this)}></input> …Run Code Online (Sandbox Code Playgroud) 我TypeError: Error resolving module specifier: d3在尝试导入 d3.js 库时遇到了问题。项目使用npm,在火狐浏览器中也遇到过这个错误。
索引.html
<!DOCTYPE html>
<html lang="en">
<header>
<meta charset="utf-8" />
<title>D3</title>
</header>
<body>
<div id="svg"></div>
<script src="./index.js" type="module"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
索引.js
import * as d3 from "d3";
Run Code Online (Sandbox Code Playgroud) Loading module from \xe2\x80\x9chttp://localhost:3000/d3.js\xe2\x80\x9d was blocked because of a disallowed MIME type (\xe2\x80\x9c\xe2\x80\x9d)我在尝试导入 d3.js 库时遇到问题。项目使用npm,在Firefox中遇到了该错误。
索引.html
\n\n<!DOCTYPE html>\n<html lang="en">\n <header>\n <meta charset="utf-8" />\n <title>D3</title>\n </header>\n\n <body>\n <div id="svg"></div>\n <script src="./index.js" type="module"></script>\n </body>\n</html>\nRun Code Online (Sandbox Code Playgroud)\n\n索引.js
\n\nimport * as d3 from "./d3.js";\nRun Code Online (Sandbox Code Playgroud)\n