@winman-f2e/nos-upload

3.0.7 • Public • Published

nos-upload

配置说明

hostendpoint有三种配置方案:

  1. 可以直接传递CDN的域名和host,比如{host: 'nosdn.127.net', endpoint: 'https://easyreadfs.nosdn.127.net'},此时将会通过CDN中转上传,适合本地未连VPN或者外网情况,但是CDN域名可能存在不稳定的问题,建议搭配合适的retryCount配置使用
  2. 可以传递NOS的内网源站域名,内网域名见内部Wiki,比如为{host: 'nos.internal.net', endpoint: 'http://nos.internal.net'},只支持http,适合本地连接了VPN或者内网服务器使用,此时需要搭配对应的objectOrigin参数,否则返回的资源url可能无法正确访问,url组装规则见下方使用示例中的注释
  3. 可以传递NOS的外网源站域名,源站域名见内部Wiki,比如为{host: 'nos.outside.net', endpoint: 'http://nos.outside.net'},此方式只支持http,适合不连VPN的本地开发场景或者外网使用场景,同样需要搭配对应的objectOrigin参数

安装和使用

$ npm install @winman-f2e/nos-upload

// nos配置请查看内部wiki文档
// 配置字段含义参照[`@nos-sdk/nos-node-sdk`](https://www.npmjs.com/package/@nos-sdk/nos-node-sdk)
const nosUpload = {
    accessKey: 'your-access-key',
    accessSecret: 'your-access-secret',
    host: 'nos.netease.com', 
    protocol: 'http',
    endpoint: 'http://nos.netease.com',
    defaultBucket: 'easyreadfs',
    objectOrigin: 'https://easyreadfs.nosdn.127.net' //可选,如果传递,将会作为返回的上传文件的url前缀,拼接方式为:objectOrigin + objectKey
} 
const getUploader = require('@winman-f2e/nos-upload')
const { uploadByContent, uploadByPath, uploadByStream } = getUploader(nosUpload)

uploadByPath(
    path.resolve(__dirname, './sentry-cli-Darwin-x86_64'), {
        prefix: '1.52.3/',
        name: 'sentry-cli-Darwin-x86_64',
        hash: false,
        retryCount: 5,
    }
).then(url => console.log('uploadFile:', url))
    .catch(err => console.log(err.message)) 

uploadByContent(
    'lalalalalaasdfsd', {
        prefix: 'fe_test/sub',
        name: 'file',
        ext: '.html',
        hash: false,
    }
).then(url => console.log('uploadText:', url))
    .catch(err => console.log(err.message))


const stream = require('stream');
const bufferData = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
const bufferStream = new stream.PassThrough();
bufferStream.end(bufferData);
//必须传入stream,以及它的length,不支持hash参数
uploadByStream(bufferStream, bufferData.length, {
  prefix: 'snailreader_node',
  name: 'screenshot' + Date.now(),
  ext: '.' + type,
}).then(url => console.log('uploadText:', url))
    .catch(err => console.log(err))

changelog

v3.1:

  • 更换上传nos-sdk为@nos-sdk/nos-node-sdk

v3.0:

  • 更换上传nos-sdk为@xgheaven/nos-node-sdk来解决cdn节点报错没有触发重试机制的问题
  • 上传的nos config字段格式修改为@xgheaven/nos-node-sdk的格式

v2.2

增加stream上传接口,使用方式见/example/upload.js:

v2

修改上传接口,使用方式见/example/upload.js,参数信息见/index.js注释

Readme

Keywords

none

Package Sidebar

Install

npm i @winman-f2e/nos-upload

Weekly Downloads

2

Version

3.0.7

License

MIT

Unpacked Size

13.9 kB

Total Files

3

Last publish

Collaborators

  • luofeiyue
  • whiskeyi
  • yousy
  • guoyeeg
  • azgaga
  • liushichuan
  • yaochen
  • shenyuan
  • aflyermin
  • ignous
  • jeekdong