微信号:nodeonly

介绍:一个全栈程序员的世界,关注最新开源技术架构,编程实践,敏捷开发,当然偶尔也会有我给朋友们的解惑文章,欢迎关注,欢迎提问

使用七牛作为simditor图片上的express router路由模块

2015-11-05 23:32 i5ting

simditor是一款非常不错的所见即所得编辑器,不过它的上传稍麻烦,尤其是集成七牛有点小坑,所以我写了这个模块,写个配置文件,2行代码就可以搞定


1. simditor-qn

simditor upload router with qiniu.com for expressjs

Artwork by i5ting.

1.1. Install

npm install --save simditor-qn

1.2. Usage

var express = require('express');
var app = express();

app.get('/', function (req, res) {
  res.send('Hello World!');
});

var simditor_qn_config = require('../simditor_qn')

require('simditor-qn')(app, simditor_qn_config);

var server = app.listen(3000, function () {
  var host = server.address().address;
  var port = server.address().port;

  console.log('Example app listening at http://%s:%s', host, port);
});

1.3. Configuration

module.exports = {
  path: '/simditor/upload',
  fileKey: 'file',
    multer:{ 
         dest: 'uploads/' 
    },
    qn:{
        accessKey: 'xxx',
        secretKey: 'yyy',
        bucket: 'mengxiaoban',
        origin: 'http://{bucket}.u.qiniudn.com',
        // timeout: 3600000, // default rpc timeout: one hour, optional
        // if your app outside of China, please set `uploadURL` to `http://up.qiniug.com/`
        // uploadURL: 'http://up.qiniu.com/',
    },
    url:function(result){
        return "http://img.mengxiaoban.cn/" + result.hash;
    }
}

说明

  • path : 默认是'/simditor/upload',是simditor里用到的路径

  • fileKey : 默认是'file',是simditor里用到的fileKey

  • multer是expressjs里上传的中间件

  • qn是fengmk2写的七牛的上传模块

1.4. Usage in Simditor

var editor = new Simditor({
  textarea: $('#editor'),
  //optional options
  upload: {
      fileObjName: 'file',
      url: '/simditor/upload',
      fileKey: 'file',
      params: {
          "token": window.qn_token
      }
  }
});

1.5. Test

npm start

打开Postman界面测试操作如下

1.6. Contributing

  1. Fork it

  2. Create your feature branch (git checkout -b my-new-feature)

  3. Commit your changes (git commit -am 'Add some feature')

  4. Push to the branch (git push origin my-new-feature)

  5. Create new Pull Request

1.7. 版本历史

  • v1.0.0 初始化版本

1.8. 欢迎fork和反馈

  • write by i5ting i5ting@126.com

如有建议或意见,请在issue提问或邮件


https://github.com/i5ting/simditor-qn


全文完

欢迎转载、分享、关注我的公众号【node全栈】


 
Node全栈 更多文章 生活如何不无聊 Nodejs入门教程ppt分享 大前端系列前言:为什么前端越来越难?越来越有意思? Gulp实战总结 node消息队列
猜您喜欢 下一个失宠的职业:公务员 【UXRen活动现场笔录】当我们谈论产品用研时我们在谈论什么? Hexo 与 Nginx 实现沉浸式多语言博客 热血编程狂欢季:Unity手动实验室(上海站)精彩花絮分享