Skip to content

Instantly share code, notes, and snippets.

@AdamJLemmon
Created February 7, 2021 16:32
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 AdamJLemmon/964f8337712158b3aaddc307635add30 to your computer and use it in GitHub Desktop.
Save AdamJLemmon/964f8337712158b3aaddc307635add30 to your computer and use it in GitHub Desktop.
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