Created
February 11, 2019 21:27
-
-
Save wnstn/bdc98f1946246f2705be34b8bf1e8f87 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('Content-Type', file.type); | |
formData.append('file', file); | |
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
thanks, was struggling with Content-Type :D