Code Monkey home page Code Monkey logo

awos-js's Introduction

AWOS-JS: Wrapper For Aliyun OSS And Amazon S3

npm

awos for golang: https://github.com/shimohq/awos

feat

  • same usage and methods for aws & oss, pretty convenient!
  • add retry strategy
  • avoid 404 status code:
    • get(key: string, metaKeys?: string[]): Promise<IGetObjectResponse | null> will return null when object not exist
    • head(key: string): Promise<Map<string, string> | null> will null when object not exist

installing

npm i awos-js --save

how to use

// for typescript
import AWOS from 'awos-js'

// for js
const AWOS = require('awos-js')

for Aliyun OSS

import { build } from 'awos-js'

// for v3.*.*
const client = build({
  storageType: 'oss',
  accessKeyID: "xxx",
  accessKeySecret: "xxx",
  bucket: "my_bucket",
  endpoint: 'endpoint',
})

// for v2.*.*
const client = new AWOS.Client({
  type: 'oss',
  ossOptions: {
    accessKeyId: 'accessKeyId',
    accessKeySecret: 'accessKeySecret',
    bucket: 'bucket',
    endpoint: 'endpoint',
  }
})

for AWS-S3 / MINIO

import { build } from 'awos-js'

// for v3.*.*
const client = build({
  storageType: 'aws',
  accessKeyID: "xxx",
  accessKeySecret: "xxx",
  // when use aws s3, endpoint is unnecessary and region must be set
  endpoint: "https://xxxx.myminio.com",
  bucket: "my_bucket",
  // when use minio, S3ForcePathStyle must be set true
  s3ForcePathStyle: true,
})

// For v2.*.*
const client = new AWOS.Client({
  storageType: 'aws',
  awsOptions: {
    accessKeyId: 'accessKeyId',
    secretAccessKey: 'secretAccessKey',
    bucket: 'bucket',
    // when use minio, S3ForcePathStyle must be set true
    // when use aws, endpoint is unnecessary and region must be set
    region: "region",
    endpoint: 'endpoint',
    s3ForcePathStyle: true,
  }
})

the available operation:

get(key: string, metaKeys?: string[]): Promise<IGetObjectResponse | null>;
getAsBuffer(key: string, metaKeys: string[]): Promise<IGetBufferedObjectResponse | null>;
put(key: string, data: string | Buffer, options?: IPutObjectOptions): Promise<void>;
del(key: string): Promise<void>;
delMulti(keys: string[]): Promise<string[]>; // return keys not deleted
head(key: string, options?: IHeadOptions): Promise<Map<string, string> | null>;
listObject(key: string, options?: IListObjectOptions): Promise<string[]>;
listDetails(key: string, options?: IListObjectOptions): Promise<IListObjectOutput>;
signatureUrl(key: string, options?: ISignatureUrlOptions): Promise<string | null>;
copy(key: string, source: string, options?: ICopyObjectOptions): Promise<void>;

Change Log

  • v3.0.0 / 2024-01-18

    • [Breaking] refactor configuration options ⚠️
    • support common prefix configuration
  • v2.0.0 / 2020-06-18

    • Breaking
      • conbine parameters meta,contentType,headers of AWOS.put into options
    • add headers option support for put method
  • v1.0.4 / 2019-12-26

    • support buffer in get and put operation
  • v1.0.3 / 2019-03-28

    • put() support contentType params
  • v1.0.2 / 2019-03-26

    • support signatureUrl() operation
  • v1.0.1 / 2019-03-19

    • bug fix: oss listObject() should return [] when options.prefix not exist in the bucket; oss listObject() maxKeys not working

awos-js's People

Contributors

neoyeelf avatar dependabot[bot] avatar aaronjan avatar huxwshimo avatar luoyjx avatar huxwfun avatar wanming avatar qingwei-li avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.