收藏FS流星,所见即所得,夏日笔记,图片上传

CollectionFS Meteor, WYSIWYG, Summernote, Image Upload

本文关键字:笔记 夏日 FS 流星 所见即所得 收藏      更新时间:2023-09-26

大家晚上好。

我一直在努力使用所见即所得的编辑器和collectionFS在Meteor中使文件上传工作。我一直在尝试使用Summernote,但我不介意使用Redactor或Froala。

显然,我没有足够的技能将所见即所得编辑器与 CollectionFS 连接以将文件上传到本地路径。

这是我的代码。

Template.postSubmit.rendered = function(){
    $('#edit').summernote();
};

Template.postSubmit.events({
  'submit #postSubmit':function(event, template) {
    FS.Utility.eachFile(event, function(file) {
      Images.insert(file, function (err, fileObj) {
        //Inserted new doc with ID fileObj._id, and kicked off the data upload using HTTP
      });
    });
  }
});
Images = new FS.Collection("images", {
  stores: [new FS.Store.FileSystem("images", {path: "img2"})]
});
Images.allow({
    insert: function() {
        return true;
    },
    update: function() {
        return true;
    },
    remove: function() {
        return true;
    },
    download: function() {
        return true;
    }
});

根据我简短的知识,我必须添加

onImageUpload: function(files, editor, welEditable) {
                        sendFile(files[0],editor,welEditable);
                       }

在夏季笔记脚本中(我吗?

我似乎无法完成这项工作!指针,指南和帮助将不胜感激...

编辑1:

Template.postSubmit.rendered = function(){
    $('#edit').summernote({
        onImageUpload: function(file) {
    FS.Utility.eachFile(event, function(file) {
      Images.insert(file, function (err, fileObj) {
        //Inserted new doc with ID fileObj._id, and kicked off the data upload using HTTP
      });
    });
  } 
    });
};

所以我已经编辑了我的代码,现在它正在工作了!它将文件上传到指定的路径。现在的问题是,1.它将立即上传图像(一旦我单击添加图像,而不是在我提交表格时(。2. 上传的图片不会显示在编辑器中。

这对

我有用:

Template.blogList.rendered = function() {
    var template = this;
    $('#summernote').summernote({
        height: 400,
        maxHeight:800,
        minHeight:250,
        onImageUpload: function(files, editor, $editable) {
            Images.insert(files[0], function (err, fileObj) {
                console.log("after insert:", fileObj._id);
                template.autorun(function (c) {
                  fileObj = Images.findOne(fileObj._id);
                  var url = fileObj.url();
                  if (url) {
                    $("#summernote").summernote("insertImage", fileObj.url(), "Image Title"); 
                    c.stop();
                  }
                });
            });
        }   
    });
}