【发布时间】:2019-10-30 05:49:05
【问题描述】:
我想 1.从前端上传文件 2. 将数据发送到后端 3. 保存在服务器上的文件夹中
1 + 2 有效,3. 也有效,但有一些并发症...
在服务器上,imports/api/bills.js 中有以下代码,我从客户端调用 writefile 方法。 该文件确实已保存,并且我在服务器上没有收到任何错误,但我在客户端上确实收到了以下错误...
为什么会这样,我该如何解决?
我已经阅读了很多关于人们尝试在浏览器中使用 fs 的 stackoverflow 问题......但这不是我所做的(对吗?)
import {Meteor} from 'meteor/meteor';
import {Mongo} from 'meteor/mongo';
import {check} from 'meteor/check';
import { DateTime } from 'luxon';
import fs from "fs"
export const Bills = new Mongo.Collection('bills');
Meteor.methods({
'bills.writefile' (blob) {
fs.writeFile('/Users/mhe/Downloads/tax/binary.png', blob, function(err) {
// If an error occurred, show it and return
if(err) return console.error(err);
// Successfully wrote binary contents to the file!
});
},
});
错误:
Exception while simulating the effect of invoking 'bills.writefile' TypeError: fs.writeFile is not a function
at MethodInvocation.bills.writefile (bills.js:75)
at livedata_connection.js:664
at Meteor.EnvironmentVariable.EVp.withValue (meteor.js?hash=33066830ab46d87e2b249d2780805545e40ce9ba:1196)
at Connection.apply (livedata_connection.js:653)
at Connection.call (livedata_connection.js:556)
at BillEntry.handleFile (BillEntry.js:88)
at Object.BillEntry.handleForm [as onChange] (BillEntry.js:68)
at onChange (FileControl.js:14)
at HTMLUnknownElement.callCallback (modules.js?hash=9581e393779a85fee7aad573af1a251d5bed8130:4483)
at Object.invokeGuardedCallbackDev (modules.js?hash=9581e393779a85fee7aad573af1a251d5bed8130:4533)
【问题讨论】: