Last active
March 25, 2018 07:56
-
-
Save Alexzanderk/62d718f18e8d716123fdb5a69e69d3bf to your computer and use it in GitHub Desktop.
send file
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
var formData = new FormData(); | |
var fileField = document.querySelector("input[type='file']"); | |
formData.append('username', 'abc123'); | |
formData.append('avatar', fileField.files[0]); | |
fetch('https://example.com/profile/avatar', { | |
method: 'PUT', | |
body: formData | |
}) | |
.then(response => response.json()) | |
.catch(error => console.error('Error:', error)) | |
.then(response => console.log('Success:', response)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment