I want to get updating info including upload file feature, for backend codes, it's above:
http.HandleFunc("/uploadHeadurlHandler", uploadHeadurlHandler)
file, image, err := r.FormFile("picture")
if err != nil {
log.Println(" -- Failed to FormFile, err:", err)
message(w, code.CodeMsg[code.CodeFormFileFailed])
return
}
frontend side codes are below as:
<form action="/userinfo" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>username</td>
<td><input type="text" disabled="disabled" name="username" value="{{.Username}}"></td>
</tr>
<tr>
<td>password</td>
<td><input type="text" name="password"></td>
</tr>
<tr>
<td>nickname</td>
<td><input type="text" name="nickname" value="{{.Nickname}}"></td>
</tr>
<tr>
<td>file</td>
<td><input type="file" id="file" name="upload" value="{{.Headurl}}"></td>
</tr>
</table>
<input type="submit" value="update">
<script>
$("#file").on("change", function () {
var formData = new FormData();
formData.append("file", $("#file")[0].files[0]);
$.ajax({
url: "/uploadHeadurlHandler",
type: "POST",
data: {picture:formData},
processData: false,
contentType: false,
success: function (response) {
alert("upload success")
}
});
});
</script>
now backend error is: Failed to FormFile, err: request Content-Type isn't multipart/form-data
I suspended there are some issues on frontend side, I'm a fresh on frontend, anyone can tell me how do I change the above frontend side.