theara
1
I would like to use any package such as convert-excel-to-json
.
But it use src file
(not upload file[0])
const json = excelToJson({
sourceFile: '/Workbook2.xlxs', // Would like to use upload file[0]
})
I tried pass with file[0]
, get error
TypeError: _fs.readFileSync is not a function
Please help me
It looks like convert-excel-to-json
only supports reading files of the filesystem, so you would need to do that on the serverside
What is file[0]
? Can you show us how that variable is defined?
theara
3
thanks for your reply.
I base on Meteor + Vue
// Vue template
<input
ref="fileInput"
type="file"
accept=".xlsx, .csv, .png, .jpg"
@change="filePicked"
>
---
// Vue Method
filePicked(event) {
const files = event.target.files
if (files[0]) {
const json = excelToJson({
sourceFile: files[0],
})
}
},
Yeah, since your code is entirely on the client side, convert-excel-to-json
won’t work
So you have two options:
- Find another package that does work on the client
- Upload it to the server side, save it to the file system, then pass it to
excelToJson
theara
5
Could you example, how to upload it to the server?
Meteor.call('method', file[0], (err, res)=>{
// .....
})
The simplest is to send the base64 encoded string as a parameter to a meteor call, but that will cause issues for larger files
Proper file uploads are a bit more difficult, so I would recommend using a package like Meteor Files (ostrio:files
)
theara
7
Thanks again, I will try.
ostrio:files
VS cfs:standard-packages