Skip to content

Instantly share code, notes, and snippets.

@victorjonsson
Created November 30, 2018 14:29
Show Gist options
  • Save victorjonsson/5e39e301f49fb845ed029cd0478847f6 to your computer and use it in GitHub Desktop.
Save victorjonsson/5e39e301f49fb845ed029cd0478847f6 to your computer and use it in GitHub Desktop.
// Turn our form data into a JSON string
const data ={
...
data: {
...
integrations: [
{type: 'integrationX' ... },
{type: 'integrationY' ... }
]
}
};
const jsonString = JSON.stringify(data);
// Our files to upload
const jsonFile = new Blob([jsonString], {type: 'application/vnd.umeakommun.basicuse+json'})
const fileUploadedByUser = document.querySelector('input[name="uploadFile"]');
// Create a form containing our files
var form = new FormData();
form.append('upload1', jsonFile, 'form.json');
form.append('upload2', fileUploadedByUser);
// Send our form to server
axios({
method: 'POST',
url: '/api/v1.0/send',
data: form,
config: {
headers: {
'Content-Type': 'multipart/form-data',
Authorization: 'Bearer ' + userAccessToken
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment