How to use qn - 10 common examples

To help you get started, we’ve selected a few qn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bimohxh / jsonon / lib / qiniu.js View on Github external
var qn = require('qn')
var localEnv = require('../config/local_env.json')
var path = require('path')

var client = qn.create({
  accessKey: localEnv.qiniu.accessKey,
  secretKey: localEnv.qiniu.secretKey,
  bucket: localEnv.qiniu.bucket,
  origin: localEnv.qiniu.origin
})


let getFullName = (file) => {
  var approot = path.resolve(path.dirname(__dirname), 'app') + '/'
  return file.split(approot)[1]
}


var qiniu = {

  // 普通上传
github linweiwei123 / multipages-generator / templates_no_framework / build / libs / qupload.js View on Github external
const path = require('path');
const qn = require('qn');
const fs = require('fs');
const chalk = require('chalk');
const { qconfig } =  require(path.resolve('mg.config.js')).upload;

var fileTotal = 0;
var fileUploadCount = 0;

var client = qn.create({
    accessKey: qconfig.ACCESS_KEY,
    secretKey: qconfig.SECRET_KEY,
    bucket: qconfig.bucket,
    origin: qconfig.origin,
});

function qnUpload(filePath,filename){
    client.uploadFile(filePath, {key: filename}, function (err, result) {
        if(err){
            console.log(chalk.red(`[Error]: 上传文件失败:${err.toString()}`));
            return;
        }
        console.log(chalk.greenBright(`[Success]: 上传文件至七牛云CDN成功!文件地址:${result.url}`));

        fileUploadCount++;
        // 上传完毕则退出
github k-dylan / easyclub / common / storage.js View on Github external
const qn = require('qn');
const config = require('../config');
const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp');

let storage;

if(config.qiniu.accessKey && config.qiniu.accessKey !== 'you access key') {
  storage = qn.create(config.qiniu);
} else {
  // 创建上传目录
  mkdirp(config.upload.path, function (err) {
    if(err) 
      throw new Error('上传文件目录创建失败!');
  });
  
  storage = {
    upload (stream, options, cb) {
      let filePath = path.join(config.upload.path, options.key);

      stream.on('end', function () {
        cb(null, {
          key: options.key,
          url: filePath
        });
github surmon-china / nodepress / np-controller / qiniu.controller.js View on Github external
/**
 * QiniuCtrl module.
 * @file 七牛控制器模块
 * @module controller/qiniu
 * @author Surmon 
 */

const qiniu = require('qn')
const CONFIG = require('app.config')
const { buildController, initController, handleSuccess } = require('np-core/np-processor')

const client = qiniu.create(CONFIG.QINIU)
const QiniuCtrl = initController()

// 获取配置列表
QiniuCtrl.GET = (req, res) => {
	const result = { uptoken: client.uploadToken() }
  handleSuccess({ res, result, message: 'upToken 获取成功' })
}

module.exports = buildController(QiniuCtrl)
github Geolage / vue-shop / server / routes / users.js View on Github external
const express = require('express')
const router = express.Router()
const fs = require('fs');
const qn = require('qn');

const User = require('../models/user');
const Good = require('../models/goods');
require('./../util/dateFormat')
// 空间名
const bucket = 'avatar-img-d';
// 七牛云
const client = qn.create({
    accessKey: 'n83SaVzVtzNbZvGCz0gWsWPgpERKp0oK4BtvXS-Y',
    secretKey: '1Uve9T2_gQX9pDY0BFJCa1RM_isy9rNjfC4XVliW',
    bucket: bucket,
    origin: 'http://ouibvkb9c.bkt.clouddn.com'
})

// 登录接口
router.post('/login', async (req, res) => {

    let {userName, userPwd} = req.body;
    const doc = await User.findOne({userName, userPwd});

    try {
        if (doc) {
            const {userId, name, avatar} = doc
            res.cookie("userId", userId, {
github frogo / blog / libs / uploader.js View on Github external
};
    let validate = function(file) {
        let error = '';
        if (options.minFileSize && options.minFileSize > file.size) {
            error = 'File is too small';
        } else if (options.maxFileSize && options.maxFileSize < file.size) {
            error = 'File is too big';
        } else if (!options.acceptFileTypes.test(file.name)) {
            error = 'Filetype not allowed';
        }
        return !error;
    };
    //七牛云存储
    let client = null;
    if (options.storage.type === 'qiniu') {
        client = qn.create(options.storage.options);
    }
    let Uploader = {};
    Uploader.delete = function(url, callback) {
        let fileName = path.basename(decodeURIComponent(url))
        console.log('删除文件', url, fileName);
        if (fileName[0] !== '.') {
            if(url.indexOf(options.storage.options.domain) > -1) {
                try {
                    client.delete(fileName, function(err) {
                        callback && callback.call(null, err);            
                    })
                } catch(e) {
                    console.log('删除7牛图片失败', e);
                    callback && callback.call(null, '删除7牛图片失败');
                }
            } else {
github djyde / cown / lib / core / upload.js View on Github external
if (bucket.isDefault) {
        usingBucket = bucket.name
        origin = bucket.domain
      }
    }
  })

  if (!usingBucket || !origin) {
    console.log('No using bucket! Use `$ cown use ` to use a bucket.')
    return 
  }

  const accessKey = usingAccount.value().accessKey
  const secretKey = usingAccount.value().secretKey

  let client = qn.create({
    accessKey, secretKey, origin,
    bucket: usingBucket
  })

  let filename = source.split('/')[source.split('/').length - 1]
  spin.start()
  client.uploadFile(source, {key: filename }, (err, result) => {
    spin.stop()
    if (err) {
      utils.showError(err)
    } else {
      console.log(colors.green('Upload success!'))
      console.log(result.url)

      if (options.copy) {
        ncp.copy(result.url)
github moajs / moa-frontend / routes / demo / bootstrap_table.js View on Github external
router.get('/', function (req, res, next) {
  var qn = require('qn');

  var client = qn.create(simditor_qn_config.qn);
  
  var token = client.uploadToken();
  console.log(token)
  
  res.render('demo/bootstrap_table', {
    title: 'index'
  });
});
github billyhoomm / x-blog / utils / cdn_sync.js View on Github external
/*
 * @Dsc:上传打包后静态文件到七牛(后续扩展成通用的webpack插件)
 * @Author: hubin 
 * @Date: 2017-11-25 00:46:16
*/
const qn = require('qn');
const path = require('path');
const fs = require('fs');
const config_qn = require('../config/config').qiniu;

const root = path.resolve(__dirname, '../public/static/');
const uploadArr = [];

let client = qn.create(config_qn);

function explorer(path){
    return new Promise((res, rej) => {
        fs.readdir(path, function(err, files){
            //err错误 , files 文件名列表包含文件夹与文件
            if(err){
                console.log('error:\n' + err);
                rej(-1)
                return;
            }
    
            files.forEach(function(file){
    
                fs.stat(path + '/' + file, function(err, stat){
                    if(err){console.log(err); return;}
                    if(stat.isDirectory()){
github xiaoshan5733 / cms / lib / uploader.js View on Github external
constructor(opts) {
    this.options = Object.assign(config.upload, opts);
    this.checkExists(this.options.tmpDir);
    this.checkExists(this.options.uploadDir);
    this.client = qn.create(this.options.storage.options);
  }

qn

Another qiniu API client for Node.js.

MIT
Latest version published 8 years ago

Package Health Score

45 / 100
Full package analysis

Popular qn functions