How to use the ali-oss 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.

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

github gzgogo / antd-pro-mobx / src / component / OSSUpload / index.js View on Github external
customRequest = async (option) => {
    this.setState({
      loading: true
    });

    const res = await getSTS();

    if (res && res.code === 0 && res.data) {
      const client = new OSS({
        ...res.data,
        expire: ''
      });

      // const fileName = `upload/${shortid.generate()}${getFileExt(option.file.name)}`;
      const fileName = `${shortid.generate()}${getFileExt(option.file.name)}`;
      const result = await client.put(fileName, option.file);

      if (result.res && result.res.status === 200) {
        option.onSuccess(result);
      } else {
        option.onError(result);
      }
    } else {
      console.error('请实现自己的STS接口,详情可参考 https://help.aliyun.com/document_detail/32077.html?spm=a2c4g.11186623.6.788.qrBaau');
    }
github mdnice / markdown-nice / src / utils / imageHosting.js View on Github external
const aliOSSPutObject = ({config, file, buffer, onSuccess, onError, images, content}) => {
  let client;
  try {
    client = new OSS(config);
  } catch (error) {
    message.error("OSS配置错误,请根据文档检查配置项");
    return;
  }

  const OSSName = getOSSName(file.name);

  client
    .put(OSSName, buffer)
    .then((response) => {
      const names = file.name.split(".");
      names.pop();
      const filename = names.join(".");
      const image = {
        filename, // 名字不变并且去掉后缀
        url: response.url,
github ecmadao / hacknical / app / utils / uploader.js View on Github external
import fs from 'fs'
import path from 'path'
import config from 'config'
import oss from 'ali-oss'
import logger from './logger'

const g = (key, defaultValue) => process.env[key] || defaultValue || ''

const store = oss({
  accessKeyId: g('HACKNICAL_ALI_ACCESS_ID'),
  accessKeySecret: g('HACKNICAL_ALI_ACCESS_KEY'),
  bucket: config.get('services.oss.bucket'),
  region: config.get('services.oss.region'),
  internal: false
})

const nextTick = (func, ...params) =>
  process.nextTick(async () => {
    try {
      await func(...params)
    } catch (e) {
      logger.error(e)
    }
  })

ali-oss

aliyun oss(object storage service) node client

MIT
Latest version published 3 months ago

Package Health Score

78 / 100
Full package analysis