How to use the qiniu.form_up function in qiniu

To help you get started, we’ve selected a few qiniu 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 mpcast / mpcast-server / src / common / service / qiniu.js View on Github external
}
    const putPolicy = new qiniu.rs.PutPolicy(options);

    // 用于前端直传直接返回 token
    if (istoken && filePath === null) {
      const putPolicy = new qiniu.rs.PutPolicy({scope: bucket});
      // console.log(putPolicy.uploadToken(mac));

      return putPolicy.uploadToken(mac);
    }

    const uploadToken = putPolicy.uploadToken(mac);

    const config = new qiniu.conf.Config();
    // config.zone = qiniu.zone.Zone_z0;
    const formUploader = new qiniu.form_up.FormUploader(config);
    const putExtra = new qiniu.form_up.PutExtra();

    // file
    function uploadFile(uploadToken, key, filePath, putExtra) {
      const deferred = think.defer();
      formUploader.putFile(uploadToken, key, filePath, putExtra, function (respErr, respBody, respInfo) {
        if (respErr) {
          throw respErr;
        }

        if (respInfo.statusCode === 200) {
          // console.log(respBody);
          deferred.resolve(respBody);

        } else {
          // console.log(respInfo.statusCode);
github arterli / CmsWing / src / controller / ext / attachment / service / qiniu.js View on Github external
scope: this.bucket + ':' + key
    };
    // console.log(options);
    const putPolicy = new qiniu.rs.PutPolicy(options);
    // 用于前端直传直接返回 token
    if (istoken && filePath == null) {
      const putPolicy = new qiniu.rs.PutPolicy({scope: this.bucket });
      // console.log(putPolicy.uploadToken(mac));
      return putPolicy.uploadToken(mac);
    }
    const uploadToken = putPolicy.uploadToken(mac);
      console.log(uploadToken);
      const config = new qiniu.conf.Config();
    // config.zone = qiniu.zone.Zone_z0;
    const formUploader = new qiniu.form_up.FormUploader(config);
    const putExtra = new qiniu.form_up.PutExtra();
    // file
    function uploadFile(uploadToken, key, filePath, putExtra) {
      const deferred = think.defer();
      formUploader.putFile(uploadToken, key, filePath, putExtra, function(respErr, respBody, respInfo) {
        if (respErr) {
          throw respErr;
        }
        if (respInfo.statusCode == 200) {
          deferred.resolve(respBody);
        } else {
          deferred.resolve(false);
        }
      });
      return deferred.promise;
    }
    return await uploadFile(uploadToken, key, filePath, putExtra);
github doramart / DoraCMS / server / routers / system.js View on Github external
//config.useHttpsDomain = true;
    // 上传是否使用cdn加速
    config.useCdnDomain = true;

    let mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
    let options = {
        scope: bucket,
        fsizeLimit: fsizeLimit,
        mimeLimit: 'image/*'
    };
    let putPolicy = new qiniu.rs.PutPolicy(options);
    let uploadToken = putPolicy.uploadToken(mac);

    let localFile = process.cwd() + "/public/" + imgkey;
    let formUploader = new qiniu.form_up.FormUploader(config);
    let putExtra = new qiniu.form_up.PutExtra();

    // 文件上传
    formUploader.putFile(uploadToken, imgkey, localFile, putExtra, function (respErr,
        respBody, respInfo) {
        if (respErr) {
            throw respErr;
        }
        if (respInfo.statusCode == 200) {
            console.log(respBody);
            res.end(origin + '/' + respBody.key);
        } else {
            console.log(respInfo.statusCode);
            console.log(respBody);
            res.end(respInfo.statusCode);
        }
    });
github pengliheng / chatroom / src / server / utils / qiniu.js View on Github external
const uploadFile = async (
  key,
  localFile,
) => {
  const config = new qiniu.conf.Config();
  config.zone = qiniu.zone.Zone_z2;
  config.useHttpsDomain = true;
  config.useCdnDomain = true;

  const formUploader = new qiniu.form_up.FormUploader(config);
  const putExtra = new qiniu.form_up.PutExtra();
  // 文件上传
  return new promise((resolve, reject) => {
    formUploader.putFile(uploadToken, key, localFile, putExtra, (err, res, respInfo) => {
      console.log('ewwefwef,', respInfo);
      if (err) {
        reject(err);
      } else {
        resolve(Object.assign({}, res, {
          url: `http://${bucketUrl}/${res.key}`,
        }));
      }
    });
  });
};
module.exports = uploadFile;
github danielwii / asuna-node-server / src / modules / core / storage / storage.qiniu.engine.ts View on Github external
const prefix = opts.prefix || yearMonthStr();
      const filename = convertFilename(file.filename);
      const filenameWithPrefix = join(prefix, filename);
      const key = join('/', bucket, filenameWithPrefix).slice(1);
      QiniuStorage.logger.log(
        `upload file to '${this.configObject.bucket}', Key: '${key}' ${r(opts)}`,
      );
      const uploadToken = new qiniu.rs.PutPolicy({ scope: this.configObject.bucket }).uploadToken(
        this.mac,
      );

      new qiniu.form_up.FormUploader().putFile(
        uploadToken,
        key,
        file.path,
        new qiniu.form_up.PutExtra(),
        (err, body, info) => {
          if (err) {
            throw new ErrorException('QiniuStorage', `upload file '${key}' error`, err);
          }
          if (info.statusCode === 200) {
            QiniuStorage.logger.log(`upload file '${r({ key, /* info, */ body })}'`);
            const resourcePath = configLoader.loadConfig(ConfigKeys.RESOURCE_PATH, '/uploads');
            const appendPrefix = join('/', this.configObject.path || '').startsWith(resourcePath)
              ? join(this.configObject.path || '')
              : join(resourcePath, this.configObject.path || '');
            resolve(
              new SavedFile({
                prefix,
                path: `${prefix}/${filename}`,
                bucket: this.configObject.bucket,
                mimetype: file.mimetype,
github zhoushaw / Instagram / service / app / service / qiniu.ts View on Github external
public async upload (stream: any) {

        let {ctx} = this

        let config = new qiniu.conf.Config();
        // 空间对应的机房
        config.zone = qiniu.zone.Zone_z2;

        // 初始化上传方法
        let formUploader  = new qiniu.form_up.FormUploader(config);
        let putExtra = new qiniu.form_up.PutExtra();
        // 获取上传token
        let uploadToken = this.getQiniuToken()
        
        formUploader.putFile(uploadToken, '', stream, putExtra, (respErr,
            respBody, respInfo) => {
            if (respErr) {
              throw respErr;
            }
            if (respInfo.statusCode == 200) {
                ctx.returnBody(200, "上传成功", {
                    key: respBody.key,
                    hash: respBody.hash,
                    url: this.publicBucketDomain
                })
            } else {
github Braised-Cakes / myh5 / server / upload / index 2.js View on Github external
let path = require('path')
var options = {
  scope: 'public',
};
var putPolicy = new qiniu.rs.PutPolicy(options);
var uploadToken = putPolicy.uploadToken(mac);


var config = new qiniu.conf.Config();
// 空间对应的机房
config.zone = qiniu.zone.Zone_z2;

let glob = require('glob')

var formUploader = new qiniu.form_up.FormUploader(config);
var putExtra = new qiniu.form_up.PutExtra();



;


function requestType(typeId) {
  return new Promise((resolve, reject) => {
    superagent.get(`http://service.eqxiu.com/m/base/file/tag/sys?bizType=${typeId}`).set("Cookie", '_ga=GA1.2.1844039418.1523173010; gr_user_id=856b28d3-7797-4ad3-bf0a-e970d2d29855; _gid=GA1.2.1183794952.1523282172; _tracker_distinct_id_=5d3727a1-f0a8-457d-9fbe-47317c4011b7; _tracker_session_id_=6915a5f5-2f33-4892-afca-d78fa7b039f7; _tracker_user_id_=4a2d8af950851f490150ef39910e18f1; UM_distinctid=162be364ec91054-02381f8078fd39-33697b04-1fa400-162be364eca1bb; rememberMe=DLcTdZGZXkAzMHU5jjaPN1v2Z6yk2xDAZWR4mm5v8zCdN91USpyM8T0IGwdxQTgxjjFv43XARdAD/hDJO9G1jiIHpv8TowKQlY4E9+yh5+AVPew0MzTHiqFdAnUhElwhcAgjaecr6Lvi49oJhxc7hBg7Nj0yJc5a6wdZyBPVJCpReJ8NrDlzEpTiuzmh0n+/4nbSMEV8wshWBPOxXtMA6lON+OgitiGHFLNVc28x6oqn/yYYWrPA/VjqJU/IRkI5mtlB4Lvtba+ZblokqnQ5QGLOxTknUZ2/VyPH+2IXomiOx56gjSQ/GO8ZO4oenIBmp3kCFh0+wZqwDHkwcojLQxuPv1w9B96gqwFJUO3IU5NJpC2kf/2vCbb/a4TmpA31GmwCQpaX5XHxHaTKfO6bN20FEvTo0wy9Q/4mcSVJoihzySyOGAVYElXKqvqcYAQpyUT8XQ/FwL7STpcHxoHkGuP91fOVbXw0l7WbjtG6dADEZ3qV24TkNgqulqUdFi1tXk46dB54EEbToGoa33eZbwK1qtFRtujaZVY9088ImXQkrZV0K2dyJJkDfhTbyteFIG3MnZfjxBm4IwagzOE0uhR39bSRBQaZZGLJ2dnRgHhMowPDnLcGNWCHTBIISLw0Rjj7qY9lLHyfprfN3uet/iPvVoIHMzXxDf4l0w3m5Wp7cw/akurO4JTZMl+9iAuJY0gmvGHImXfz7W3XuEfNoP9nKPCtNVj4ewLE8FoDIjKlejDaUsR3R+2peNRJ4XGzAUysUU0JklxzlBfq3pKzWRtb4RGmFTz8+CtJQnTdocQ6V5ZC96BCSQ1gljLjzfG8JDxQ7Wj0KxUmMwC8+6L495Xg8iowmWyYdv7AHI8ippkAdkjeJ5oPsVxG4KdhD7gf2TACM5KgcezXx89tR1pMo0GDhJOWWO3PoEOCZPWbaLFEHd6vh5jyLDraUWi8KqW5MvB7pAuqqhe2Ftq2/qFwVU+xVCTpWYSUfAfNHDfGp2yomKcMckkdh5IJALDmRKvGiBSRfo/v2Q9GOGlb9PaT4gqudN2FWFWORhk0Y4Q3WW9EP++7sGOyIhjfBXf1amphc2BZG0YumdJIQoghz9FPcopQsa2HCtHF+kWuTDutVQOWAc5TcAApAMwakrYEeyyUqVFKJwZlVvu6rvpwA3+Ji3VvW2pDWsREHo5cYGLrb2KY5yffRfEUvANargC79qzamx4e5Zn3vJBsa5DjNrv46lWSEbOwj+edsYYUBHRi8GFFGA02MCpimqWls76witVUwHE5BLYA379ZP35HMr11wwmIgvIVvr76tRbMydVFKsoO5qbSbkfnD1YNtfjoqSB84OCwlrUkNU3TKXnhjnFvOg==; _tracker_launch_=1; JSESSIONID=87f8dac50f5443b3a643addcbc60dc84; gr_session_id_a17a66c1107ba80b=6aaada5d-7096-4d1a-82db-c5b19f30cf06; _gat=1').set({
      "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
      'Content-Type': 'application/x-www-form-urlencoded'
    }).end(function (err, res) {
      if (err) {
        throw err
      }
      if (err) {
github naihe138 / naice-blog-koa / src / utils / upload.js View on Github external
const upToQiniu = (filePath, key) => {
  const accessKey = myConfig.QINIU.accessKey
  const secretKey = myConfig.QINIU.secretKey
  const mac = new qiniu.auth.digest.Mac(accessKey, secretKey)
  const options = {
    scope: myConfig.QINIU.bucket
  }
  const putPolicy = new qiniu.rs.PutPolicy(options)
  const uploadToken = putPolicy.uploadToken(mac)

  const config = new qiniu.conf.Config()
  // 空间对应的机房
  config.zone = qiniu.zone.Zone_z2
  const localFile = filePath
  const formUploader = new qiniu.form_up.FormUploader(config)
  const putExtra = new qiniu.form_up.PutExtra()
  // 文件上传
  return new Promise((resolved, reject) => {
    formUploader.putFile(uploadToken, key, localFile, putExtra, function (respErr, respBody, respInfo) {
      if (respErr) {
        reject(respErr)
      } else {
        resolved(respBody)
      }
    })
  })
}