DiegoZoracKy / convert-excel-to-json

Convert Excel to JSON, mapping sheet columns to object keys.
MIT License
290 stars 91 forks source link

How to use with `Upload file: file[0]`? #13

Closed thearabbit closed 6 years ago

thearabbit commented 6 years ago

I would like to convert from upload excel file

      const files = event.target.files
      .....
      const result = excelToJson({
        sourceFile: file[0],
      })

But don't work

image

DiegoZoracKy commented 6 years ago

Based on the log you sent, it seems that the error is not related to this module. Take a look at readFileSync is not a function. Are you trying to use it on the front-end?

thearabbit commented 6 years ago

Yes, now I know it use on Server! but I not clear how to upload my excel file to Server Meteor Method. I base on Meteor JS

// Client
const files = event.target.files
Meteor.call('methodName', files[0], (err, res) => {

})
---
// Server
Meteor.methods({
   methodName(file){
       const json = excelToJson({
         sourceFile: file,
      })
      console.log(json)
   }
})

But not work, please help me (how to pass file[0] to server)

DiegoZoracKy commented 6 years ago

I would really help you if I could. But I don't know much about Meteor. I suggest you to forget about the conversion for a while, and to focus only on getting the uploaded file path on the server. Write a code where you will only console.log the received file path and then you try to move forward with the conversion.

After you can get the uploaded file path on the server, if you still have a problem with the conversion, feel free to ping me here.

thearabbit commented 6 years ago

I tried to use FileReader via `Meteor forum to update file

var reader = new FileReader()
      reader.addEventListener(
        'load',
        function() {
           Meteor.call('methodName', reader.result)
        },
        false
      )
      reader.readAsDataURL(file)
      // reader.readAsText(file)
      // reader.readAsArrayBuffer(file)
      // reader.readAsBinaryString(file)

but still not work

thearabbit commented 6 years ago

Other hand, could you example with

DiegoZoracKy commented 6 years ago

See if the example section here can help you:

https://www.npmjs.com/package/express-fileupload

On Mon, Aug 20, 2018, 10:49 AM Yuom Theara notifications@github.com wrote:

Other hand, could you example with

  • Rest API (Express)
  • Axios (HTTP client) Bc I could use this instead Meteor Method

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/DiegoZoracKy/convert-excel-to-json/issues/13#issuecomment-414322655, or mute the thread https://github.com/notifications/unsubscribe-auth/AB_oP9v_iCsabZVDOF_-wIsZLOX7BSHsks5uSr5kgaJpZM4WDUv0 .

thearabbit commented 6 years ago

Now I use Meteor File Upload, and then read file to source