Last active
February 11, 2019 21:16
-
-
Save wnstn/2e2c36bd3f934425b29d06854b0d4b86 to your computer and use it in GitHub Desktop.
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
const uploadInput = document.querySelector('input[type="file"]'); | |
const awsFormData = JSON.parse(uploadEl.getAttribute('data-form-data')); | |
const formData = new FormData(); | |
Object.keys(awsFormData).forEach((key)=>{ | |
formData.append(key, awsFormData[key]); | |
}); | |
uploadInput.addEventListener('change', function(ev){ | |
ev.preventDefault(); | |
const file = ev.target.files[0]; | |
formData.append('file', file); | |
formData.append('Content-Type', file.type); | |
const config = { | |
method: "POST", | |
headers: new Headers({ | |
"Accept": "application/xml" | |
}), | |
body: formData, | |
}; | |
return fetch(url, config) | |
.then(response => response.text()) | |
.then((xml) => { | |
// decode xml and handle response | |
}) | |
.catch((e) => console.error.bind(console)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment