0.0.10 • Published 11 months ago

@annexwu-packages/cos-upload-utils v0.0.10

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

@annexwu-packages/cos-upload-utils

Usage

const fs = require('fs');
const { CosUpload } = require('@annexwu-packages/cos-upload-utils');

async function test() {
  const cosUpload = new CosUpload({
    cos: {
      SecretId: 'xxx',
      SecretKey: 'xxx',
    },
    putObjectLimit: 5 * 1024 * 1024 * 1024,
    defaultChunkSize: 8 * 1024 * 1024,
  });

  const result = await cosUpload.runTask({
    object: {
      Bucket: 'xxx',
      Region: 'xxx',
      Key: 'xxx',
      ContentLength: 1024,
    },
    getRangeReadStream: (start, end) => {
      return fs.createReadStream('xxx', { start, end: end - 1 });
    },
    getReadStream: () => {
      return fs.createReadStream('xxx');
    },
  });
}

test();

API

CosUpload

Create a cos upload controller

const fs = require('fs');
const { CosUpload } = require('@annexwu-packages/cos-upload-utils');

async function test() {
  const cosUpload = new CosUpload({
    cos: {
      SecretId: 'xxx',
      SecretKey: 'xxx',
    },
    putObjectLimit: 5 * 1024 * 1024 * 1024,
    defaultChunkSize: 8 * 1024 * 1024,
  });

  const result = await cosUpload.runTask({
    object: {
      Bucket: 'xxx',
      Region: 'xxx',
      Key: 'xxx',
      ContentLength: 1024,
    },
    getRangeReadStream: (start, end) => {
      return fs.createReadStream('xxx', { start, end: end - 1 });
    },
    getReadStream: () => {
      return fs.createReadStream('xxx');
    },
  });
}

test();