Meteor方法文件阅读器:该参数不是blob
我正在上传一个带有collectionFS的csv文件,然后我需要解析这个文件 我就是这样做的:Meteor方法文件阅读器:该参数不是blob,meteor,filereader,Meteor,Filereader,我正在上传一个带有collectionFS的csv文件,然后我需要解析这个文件 我就是这样做的: Template.fsbanks.events "change .myFileInput": (event, template) -> FS.Utility.eachFile event, (file) -> Fsbanks.insert file, (err, fileObj) -> if err Notifications.danger
Template.fsbanks.events "change .myFileInput": (event, template) ->
FS.Utility.eachFile event, (file) ->
Fsbanks.insert file, (err, fileObj) ->
if err
Notifications.danger err
else
console.log "File saved"
console.log fileObj
Meteor.call "importTransactions", file, (error, result) ->
然后我想要一些流星法:
Meteor.methods
importTransactions: (file) ->
reader = new FileReader
console.log file
reader.readAsText file
reader.onload = (event) ->
data = $.csv.toObjects(event.target.result)
console.log "File read #{data}"
_.map data, (transaction) ->
console.log transaction
t = {}
date = transaction["Value date"]
date_array = date.split("/")
new_date = date_array[2] + "-" + date_array[1] + "-" + date_array[0]
# console.log new_date
t["account_nbr"] = transaction["Account number"]
t["value_date"] = new Date new_date
t["amount"] = transaction["Amount in the currency of the account"].replace(/\s/g, '')
# console.log t["amount"]
t["description"] = transaction["Description"]
Meteor.call "createTransaction", t, t["Entry number"], (error, entry_nbr) ->
if error
console.log error
else
console.log id
createTransaction: (transaction, entry_nbr) ->
Transactions.upsert
entry_nbr: entry_nbr
,
$set: transaction
return entry_nbr
执行此操作时,collectionFS insert可以正常工作
但是我对insertTransaction服务器方法有一个问题:
Failed to execute 'readAsText' on 'FileReader': The argument is not a Blob.
如果我在客户端运行完全相同的代码,它就会工作
运行代码服务器端需要做哪些更改?这是我结束时使用的代码。它的功能,但我真的不知道为什么 在我的模型中,共享客户端/服务器:
Meteor.methods
importTransactions: (file) ->
reader = new FileReader
console.log file
reader.readAsText file
reader.onload = (event) ->
data = $.csv.toObjects(event.target.result)
console.log "File read #{data}"
_.map data, (transaction) ->
console.log transaction
t = {}
selectValues = {}
date = transaction["Value date"]
date_array = date.split("/")
new_date = date_array[2] + "-" + date_array[1] + "-" + date_array[0]
# console.log new_date
selectValues["account_nbr"] = transaction["Account number"]
selectValues["value_date"] = new Date new_date
selectValues["entry_nbr"] = parseInt transaction["Entry Number"]
t["amount"] = transaction["Amount in the currency of the account"].replace(/\s/g, '')
# console.log t["amount"]
t["description"] = transaction["Description"]
Meteor.call "createTransaction", t, selectValues, (error, entry_nbr) ->
if error
console.log error
else
console.log id
在服务器上:
Meteor.methods
createTransaction: (values, upsertValues) ->
if upsertValues
console.log "upserting transaction"
console.log "transaction: #{values}"
console.log "Values: #{upsertValues["entry_nbr"]}"
Transactions.upsert upsertValues
,
$set: values
, (err, nbr) ->
if err
console.log err
else
console.log "upsert successful #{nbr}"
else
Transactions.insert values
, (err, nbr) ->
if err
console.log err
else
console.log "insert successful #{nbr}"
你解决过这个问题吗?我还试图在不插入文件的情况下解析文件,但遇到了问题。如果你有时间,请告诉我。谢谢它很旧了,但似乎还能用。我会在答案中添加代码,但老实说,我不记得是什么让它起作用了。我会试试看。谢谢你的发帖。