Skip to content

Instantly share code, notes, and snippets.

@wnstn
Last active February 11, 2019 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wnstn/2e2c36bd3f934425b29d06854b0d4b86 to your computer and use it in GitHub Desktop.
Save wnstn/2e2c36bd3f934425b29d06854b0d4b86 to your computer and use it in GitHub Desktop.
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