reboottime / WebDevelopment

Some notes, thoughts and articles aggregated here about UI/UX and web development.
6 stars 0 forks source link

CSV File Uploading Practices between Frontend and Backend #152

Open reboottime opened 11 months ago

reboottime commented 11 months ago

Introduction to CSV and its applications, challenges

what is CSV and what it used for

CSV is an acronym for Comma-Separated Values. CSV is commonly used for data exchange between different applications, importing and exporting data from spreadsheets, etc.

Structure of CSV

Consideration and Challenges

reboottime commented 11 months ago

Sample solutions for above solution directions


1. Chunking a large CSV file

function processCSVChunk(chunk) {
  // Process the CSV chunk here
  // you can split the chunk into lines
  // or covert the chunk into a plain text using chunk.text
}

async function processCSVFile(file) {
  const chunkSize = 1024 * 1024;
  let offset = 0;

 // Read the file slice
  while (offset < file.size) {
    const chunk = file.slice(offset, offset + chunkSize);
    const textChunk = await chunk.text();

    await processCSVChunk(textChunk);

    offset += chunkSize;
  }

  console.log('CSV processing completed');
}

2. Using streaming solution

Very similar to the solution of using chunk, and also potentially has the same issue of breaking a row into two different chunks and result in parsing error.

reboottime commented 11 months ago

Suggested NPM Packages for Addressing the above Challenges

The package solution I gravitate towards is PapaParse, owing to its adept handling of the challenges mentioned above. Moreover, it also supports the functionality of aborting CSV file parsing after producing a set number of results.

reboottime commented 11 months ago

Crafting the Workflow

What are expected


When orchestrating the exchange of data between distinct systems using CSV as the medium, user expects:

In response to these user expectations, the design of CSV uploading systems demands consideration in these aspects:


The Workflow

image

Performance considerations


The UI considerations

Provide user instruction and guidelines using step workflows