How to use the ali-oss.Wrapper function in ali-oss

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

github aliyun / serverless-aliyun-function-compute / test / project / src / ossTriggerHandler.js View on Github external
module.exports = (event, context, callback) => {
  const parsedEvent = JSON.parse(event);
  const ossEvent = parsedEvent.events[0];
  // Required by OSS sdk: OSS region is prefixed with "oss-", e.g. "oss-cn-shanghai"
  const ossRegion = `oss-${ossEvent.region}`;
  // Create oss client.
  const client = new oss({
    region: ossRegion,
    bucket: ossEvent.oss.bucket.name,
    // Credentials can be retrieved from context
    accessKeyId: context.credentials.accessKeyId,
    accessKeySecret: context.credentials.accessKeySecret,
    stsToken: context.credentials.securityToken
  });

  const objKey = ossEvent.oss.object.key;
  console.log('Getting object: ', objKey);
  client.get(objKey).then(function(val) {
    const newKey = objKey.replace('source/', 'processed/');
    return client.put(newKey, val.content).then(function (val) {
      console.log('Put object:', val);
      callback(null, val);
    }).catch(function (err) {
github yedaodao / hexo-deployer-aliyun / lib / deployer.js View on Github external
'Example:',
            '  deploy:',
            '    type: aliyun',
            '    bucket: yourBucketName',
            '    region: yourOSSregion',
            '    accessKeyId: yourAccessKeyId',
            '    accessKeySecret: yourAccessKeySecret',
            '',
            'For more help, you can check the docs: ' + chalk.underline('http://hexo.io/docs/deployment.html') + ' and ' + chalk.underline('https://help.aliyun.com/document_detail/31867.html?spm=5176.doc31950.2.1.WMtDHS')
        ];
        console.log(help.join('\n'));
        log.error('config error');
        return;
    }

    var client = new OSS({
        region: args.region,
        accessKeyId: args.accessKeyId,
        accessKeySecret: args.accessKeySecret,
        bucket: args.bucket
    });

    log.info('Uploading files to Aliyun...');

    // get all files sync
    traverseFiles(publicDir, function (file) {
        uploadFileList.push({
            uploadPath: getUploadPath(file, pathFn.basename(publicDir)),
            file: file
        });
    });
github dzy321 / file-upload / lib / oss.js View on Github external
// {
  //    accessKeyId:     "keyId",
  //    accessKeySecret: "secret",
  //    bucket:          "terminus-designer",
  //    region:          "oss-cn-hangzhou"
  // }
  let { accessKeyId, accessKeySecret, bucket, region, targetProtocol, attachment, targetHost } = options

  if (!targetHost) {
    targetHost = `${bucket}.${region}.aliyuncs.com`
  }

  if (!(accessKeyId && accessKeySecret && bucket && region)) {
    throw new Error("Missing option in options: [accessKeyId, accessKeySecret, bucket, region]")
  }
  const store = new oss(options)

  return {
    put: async (filename, file) => {
      await util.fileResolve(file)
      const opts = attachment === true ? {
        headers: {
          "Content-Disposition": `attachment;filename=${encodeURIComponent(file.filename)};filename*=UTF-8''${encodeURIComponent(file.filename)}`
        }
      } : undefined
      return store.put(filename, file.path, opts)
    },
    get: (result) => {
      Object.keys(result).map(filename => {
        return result[filename] = `${targetProtocol ? `${targetProtocol}:` : ""}//${targetHost}/${result[filename]}`
      })
      return result
github LTTPP / know / Wit / alicloud / ali.services.auth.js View on Github external
function kv(key, callback) {
    const ossclient = new OSS({
        region: 'oss-cn-beijing',
        accessKeyId: accessKeyId,
        accessKeySecret: accessKeySecret,
        bucket: bucket
    });

    ossclient.get(key).then(function (res) {
        const value = res.content; // plain text
        if (isValidToken(value.toString())) {
            callback(null, value);
        } else {
            renew((newValue) => { // plain text
                // process expires_in value
                const v = normalize(newValue); // JSON object
                // refresh the OOS
                ossclient.put(key, Buffer.from(stringify(v))); // buffer type
github awesomes-cn / api / lib / aliyun.js View on Github external
var OSS = require('ali-oss')

var localEnv = require('../config')
const request = require('request')

var client = new OSS.Wrapper({
  region: localEnv.alioss.region,
  accessKeyId: localEnv.alioss.AccessKeyId,
  accessKeySecret: localEnv.alioss.AccessKeySecret
})

var aliyun = {
  // 上传普通文件
  upload: async (file, filename) => {
    client.useBucket(localEnv.alioss.bucket)
    return await client.put(filename, file)
  },

  // 上传网络图片
  uploadUrl: async (url, filename) => {
    var stream = require('stream')
    var a = new stream.PassThrough()
github bimohxh / webon / lib / aliyun.js View on Github external
var OSS = require('ali-oss')
var Helper = require('./helper')

var localEnv = Helper.readLocalEnv()


const fetchConfVal = (str) => {
  let matchs = str.match(/^<(.+)>$/) 
  return matchs ? process.env[matchs[1]] : str
}

var client = new OSS.Wrapper({
  region: localEnv.aliyun.region,
  accessKeyId: fetchConfVal(localEnv.aliyun.accessKeyId),
  accessKeySecret: fetchConfVal(localEnv.aliyun.accessKeySecret)
})

var aliyun = {
  // 上传
  upload: (file, removePrefix) => {
    return new Promise(resolve => {
      let fullname = Helper.uploadFileName(file, removePrefix)
      client.useBucket(localEnv.aliyun.bucket)
      client.put(fullname, file).then((data) => {
        resolve()
      })
    })
  }
github LTTPP / know / Wit / alicloud / ali.services.tobase64.js View on Github external
function fromOssObject(key, callback) {
    const ossclient = new OSS({
        region: 'oss-cn-beijing',
        accessKeyId: accessKeyId,
        accessKeySecret: accessKeySecret,
        bucket: bucket
    });

    ossclient.get(key).then(function (res) {
        const buf = res.content;
        const b64str = buf.toString('base64');
        ossclient.delete(key);
        callback(null, b64str);
    }).catch(function (err) {
        callback(err);
    });
}
github MT-Libraries / ghost-oss-store / index.js View on Github external
constructor (config) {
    super(config)
    this.options = config || {}
    this.client = new OSS(this.options)
  }
github LTTPP / know / Wit / alicloud / ali.services.tobase64.client.js View on Github external
const put = function (objectKey, pathToFile) {
    let ossclient = new OSS({
        region: 'oss-cn-beijing',
        accessKeyId: auth.ali.accessKeyId,
        accessKeySecret: auth.ali.accessKeySecret,
        bucket: bucket
    });

    ossclient.useBucket(bucket);
    return ossclient.put(objectKey, pathToFile);
};

ali-oss

aliyun oss(object storage service) node client

MIT
Latest version published 8 months ago

Package Health Score

75 / 100
Full package analysis

Similar packages