I have cfs collection for file uploading. I have already used this in the template and its working well. Now I have to use this react.component but its showing this error Uncaught ReferenceError: fsFile is not defined
. I have added FS.Collection but its still showing error. Its working in when I using the template but not working in the react component. How can I solve this?
import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';
import React from 'react';
import Switch from 'react-switch';
import {Events} from './../../api/events';
import DatePicker from "react-datepicker";
import moment from "moment";
import "react-datepicker/dist/react-datepicker.css";
export default class AddEvent extends React.Component{
EventForm(e){
e.preventDefault();
let eventTitle = e.target.title.value;
let file = $('#projectImage').get(0).files[0];
if(file){
fsFile = new FS.File(file);
ProjectImages.insert(fsFile, function(err, result){
if(!err){
var projectImage = '/cfs/files/ProjectImages/' + result._id;
// Insert Project
Events.insert({
name: eventTitle,
projectImage: projectImage
});
}
});
} else {
// Insert Project
Events.insert({
name: eventTitle
});
}
}
render(){
return(
<div className="tab-pane fade" id="upEvents">
<form className="upload-event-from" onSubmit={this.EventForm.bind(this)}>
<div className="form-group">
<input type="text" className="form-control" id="event_title" placeholder="Event Title" name="title" />
<span className="error-message eventTitle"></span>
</div>
<div className="form-group fg-icon">
<label>Upload Image</label>
<input type="file" className="form-control" name="projectImage" id="projectImage" />
<img id="blah" src="#" alt="your image" />
</div>
<center>
<button type="submit" className="btn app-btn">Publish</button>
</center>
</form>
</div>
);
}
}
The issue in that fsFile = new FS.File(file);
line, you didn't declare the let
but below of this line you called this again, I hope the issue happening from there, use like below
let fsFile = new FS.File(file);
ProjectImages.insert(fsFile, function(err, result){
....