Created
February 7, 2021 16:32
-
-
Save AdamJLemmon/964f8337712158b3aaddc307635add30 to your computer and use it in GitHub Desktop.
This file contains 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 fs = require('fs') | |
const FormData = require('form-data') | |
const axios = require('axios') | |
const orgId = process.env.ORG_ID | |
const apiURl = process.env.API_URL || 'https://api.staging.trybe.id' | |
const readCsv = async ({ path }) => { | |
return new Promise((resolve, reject) => { | |
fs.readFile(path, async (err, data) => { | |
if (err) { | |
console.error(err) | |
return | |
} | |
resolve(data) | |
}) | |
}) | |
} | |
const uploadLabResults = async ({ path='./exampleLabResults.csv' } = {}) => { | |
const results = await readCsv({ path }) | |
const resultsForm = new FormData() | |
resultsForm.append('results', results) | |
const { status, data } = await axios.post( | |
`${apiURl}/provider/uploadLabResults/${orgId}`, | |
resultsForm, | |
{ | |
headers: { | |
'vcx-api-key': process.env.API_KEY, | |
/** | |
* @NOTE | |
* ...resultsForm.getHeaders() = 'content-type': 'multipart/form-data; boundary=--------------------------135464684664992951325057' | |
*/ | |
...resultsForm.getHeaders() | |
}, | |
} | |
) | |
console.log({ status, data }) | |
} | |
uploadLabResults() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment