1

So, I receive a .xslx file, parse it and get the first column, turn the values into DataMatrix barcode images and then save it all in a .zip archive:

const express = require('express')
const fileUpload = require('express-fileupload');
const xlsx = require('xlsx')
const bwipjs = require('bwip-js');
const admzip = require('adm-zip')

const app = express()

app.use(fileUpload());

app.post('/create', async (req, res) => {
    if(req.files.sampleFile) {
        var file = xlsx.read(req.files.sampleFile.data)
        var worksheet = file.Sheets[file.SheetNames[0]]
        var counter = 1

        var zip = new admzip()

        for(let z in worksheet) {
            if(z.toString()[0] == "A") {
                bwipjs.toBuffer({
                    bcid: 'datamatrix',       // Barcode type
                    text: worksheet[z].v,    // Text to encode
                    scale: 3,               // 3x scaling factor
                    padding: 10,
                    textxalign: 'center',        // Always good to set this
                    backgroundcolor: 'ffffff'
                }, (err, png) => {
                    if(err) {
                        console.log(err)
                    } else {
                        zip.addFile(`barcode${counter}.png`, png, "", 0400)
                        counter++
                    }
                })
            }
        }

        console.log('done zipping')
        zip.writeZip(__dirname + 'stickers.zip')
        res.send('Check fs and console')
    } else {
        res.send("no sample file")
    }
app.listen(3000, () => {
    console.log("Armed and ready on port 3000. Address: http://127.0.0.1:3000/")
})

So everything works fine right up until I try to save the .zip file. I just don't get anything. No error message, no file, nothing.
If nothing is throws errors, what's wrong?

Edit: the .xlsx file contains over 600+ entries

The Developer
  • 319
  • 2
  • 4
  • 15

0 Answers0