We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
1 parent36ba50f commitc9868bbCopy full SHA for c9868bb
public/index.html
@@ -14,7 +14,31 @@ <h1> Image Upload</h1>
14
<inputtype="file"name="avatar"id="image">
15
<inputtype="submit"value="Upload Image">
16
</form>
17
+
18
+<h1> Image Upload By JavaScript</h1>
19
20
+<inputtype="text"name="fullname"id="fullName">
21
+<inputtype="file"name="avatar"id="avatar">
22
23
24
</body>
25
+<script>
26
+document.getElementById('avatar').onchange=function(e){
27
+fileUpload(e);
28
+}
29
+functionfileUpload(e){
30
+// this method you can use with any JS frontend library
31
+letformData=newFormData();
32
+formData.append('avatar',e.target.files[0]);
33
+// this first arg is == 'name' attribute
34
+formData.append('fullname',document.getElementById('fullName').value);
35
+fetch('/image',{
36
+method:'POST',
37
+body:formData
38
+}).then(response=>{
39
+console.log(response)
40
+})
41
42
43
+</script>
44
</html>
uploads/html
2.52 KB