Search code examples
javascriptcsvstreamingpapaparse

Access "private" git hub file using papaparse


I am trying to access a "private" csv file using pappaparse.

My first attempt was to set the downloadRequestHeaders with {Authorization: "token " + token }, but it did not work. My second attempt was to use CHAT GPT suggestion of setting up a "stream" with access token. but that did not work either.

Is there any example of pappaparse accessing such private files?

My attempt below

const downloadRequestHeaders = {
    authorization: "token " + token,
}

const p = await new Promise((resolve) => {
    Papa.parse(file, {
        delimiter: ",",
        download: true,
        worker: true,
        header: true,
        skipEmptyLines: true,
        downloadRequestHeaders,
        step: (row) => stepFunction(row),
        error: (err, file) => errorFunction(err, file),
        complete: (result, file) => {
            completeFunction(result, file)
            resolve(resolveValue)
        },
    })
})

the returned value from stepFunction is row = {data, errors, meta} where data = { __parsed_extra: [""], "{": " \"name\": \"plan.csv\"" } and meta = {aborted: false, cursor: 3226, delimiter: ",",fields: ["{"], linebreak: "↵",renamedHeaders: null, truncated: false}

The normal returned value is as follows: data: { head1: val1, head2: val2... } and meta = {aborted: false, cursor: 3226, delimiter: ",",fields: [head1, head2,...], linebreak: "↵",renamedHeaders: null, truncated: false}


Solution

  • I was able to solve this issue myself. I added Accept: "application/vnd.github.v3.raw" in the downloadRequestHeaders and papaparse read the private file.