npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gaoding/oss-uploader

v1.0.10

Published

upload file through ali-oss

Downloads

39

Readme

oss-upload

upload file by ali-oss

Installation

npm install -S @gaoding/oss-uploader

Node Usage

example:

const OSSUploader = require('@gaoding/oss-uploader');

const ossUpload = new OSSUploader({
    accessKeyId: '<accessKeyId>',
    accessKeySecret: '<accessKeySecret>',
    bucket: '<bucket>',
    region: '<oss region>',
    internal: false
});

ossUploader.upload(file, key, {
    meta: {
        'Content-Type': 'font/woff'
    }
})
.then(result => {
    // result:
    // {
    //   name: 'test/index.e28ef59.js',
    //   url: 'https://test-cdn.oss-cn-hangzhou.aliyuncs.com/test/index.e28ef59.js',
    //   res: {
    //      status: 200,
    //      statusCode: 200,
    //      headers: {
    //          server: "Tengine",
    //          content - type: "application/json",
    //          content - length: "148",
    //          connection: "keep-alive",
    //          date: "Tue, 31 Mar 2015 11:06:32 GMT",
    //          "last-modified": "Mon, 30 Mar 2015 10:46:35 GMT"
    //      },
    //      size: 148,
    //      aborted: false,
    //      rt: 461,
    //      keepAliveSocket: false
    //   }
    // }
});

Browser Usage


import OSSUploader from '@gaoding/oss-uploader';

const ossUploader = new OSSUploader({
    key: '0/dianshang/20190214-111136-66fa.png',
    access_key: '<access_key>',
    action: '//st-gdx.dancf.com',
    oss_action: '//dancf-st-gdx.oss-cn-hangzhou.aliyuncs.com',
    policy: '<policy from server>'
    signature: '<signature from server>'
});
ossUploader.upload(file, options)
.then(result => {
    // result:
    // {
    //   key: '0/dianshang/20190214-111136-66fa.png'
    // }
});

Create An Instance In Node

options:

  • accessKeyId {String} access key you create on aliyun console website
  • accessKeySecret {String} access secret you create
  • bucket {String} the bucket name
  • region {String} the bucket data region location, default is oss-cn-hangzhou
  • internal {Boolean} access OSS with aliyun internal network or not, default is false

API

.upload(file, key, options)

Upload local files to cdn using secret key, return Promise.

parameters:

  • file {String|Buffer} object local path
  • key {String} object name store on OSS, if missing, it will be given a random value
  • options {Object} other information
    • bucket {String} the bucket name
    • meta {Object} including HTTP header and custom meta information

.getImageInfo(key)

Get target image's information. (format,size,width,height)

parameters:

  • key {String} object name store on OSS

.uploadStream(stream, key, bucket)

Upload stream file.

parameters:

  • stream {ReadStream} object ReadStream content instance
  • key {String} object name store on OSS
  • bucket {String} the bucket name

.uptoken(key)

Generate token.

parameters:

  • key {String} object name store on OSS

Create An Instance In Browser

options:

  • key {String} object name store on OSS
  • access_key {String} access key you create on aliyun console website
  • action {String} oss upload address
  • oss_action {String} the internal oss upload address, there may be an intranet bonus (East China region)
  • policy {String} upload certificate
  • signature {String} upload certificate

API

.upload(file, options)

Upload file,return Promise.

parameters:

  • file {String|Buffer|ReadStream|File|Blob} object local path, content buffer or ReadStream content instance use in Node, Blob and html5 File
  • options {Object}
    • filename {String}
    • action {String} upload url,
    • data {String} formData,
    • timeout {Number} upload timeout,
    • headers {Object},
    • withCredentials {Boolean},
    • onProgress {Function}
    • imageActionUrl {String} the url to compress image, default is //image-uploader.dancf.com/

.abort(file)

Abort upload request.

parameters:

  • file {String|Buffer|ReadStream|File|Blob} uploading file