Created
July 10, 2017 05:39
-
-
Save lepture/c46aaca9f43e20cda9fe7c0701546316 to your computer and use it in GitHub Desktop.
test-golang-fetch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Test Upload</title> | |
</head> | |
<body> | |
<form action="/upload" method="post" enctype="multipart/form-data"> | |
<input type="file"> | |
<button>Submit</button> | |
</form> | |
<script> | |
var form = document.querySelector('form'); | |
var input = document.querySelector('input'); | |
form.addEventListener('submit', function(e) { | |
e.preventDefault(); | |
var body = new FormData(); | |
body.append('file', input.files[0]); | |
fetch('/upload', {method: 'POST', body: body}).then(function(resp) { | |
console.log(resp.status); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net/http" | |
"log" | |
) | |
func main() { | |
mux := http.NewServeMux() | |
mux.Handle("/", http.FileServer(http.Dir("."))) | |
log.Fatal(http.ListenAndServe(":8010", mux)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ok |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment