# @winman-f2e/nos-upload

> ## 配置说明 `host`及`endpoint`有三种配置方案： 1. 可以直接传递CDN的域名和host，比如`{host: 'nosdn.127.net', endpoint: 'https://easyreadfs.nosdn.127.net'}`，此时将会通过CDN中转上传，适合本地未连VPN或者外网情况，但是CDN域名可能存在不稳定的问题，建议搭配合适的retryCount配置使用 2. 可以传递NOS的内网源站域名，内网域名见内部Wiki，比如为`{host: 'nos.internal.n

Latest version **3.0.7** (published 2022-11-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @winman-f2e/nos-upload
pnpm add @winman-f2e/nos-upload
yarn add @winman-f2e/nos-upload
bun add @winman-f2e/nos-upload
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.7 |
| Published | 2022-11-30 |
| First published | 2018-02-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 13.6 KB |
| Known vulnerabilities | 0 (+15 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | luofeiyue, whiskeyi, yousy, guoyeeg, azgaga, liushichuan, yaochen, shenyuan, aflyermin, ignous, jeekdong |

## Links

- npm: https://www.npmjs.com/package/@winman-f2e/nos-upload
- npm.io page: https://npm.io/package/@winman-f2e/nos-upload

## Dependencies (6)

- [debug](https://npm.io/package/debug.md) ^3.1.0
- [write](https://npm.io/package/write.md) ^1.0.3
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.5
- [node-forge](https://npm.io/package/node-forge.md) ^0.7.1
- [nos-node-sdk](https://npm.io/package/nos-node-sdk.md) 0.0.2
- [@nos-sdk/nos-node-sdk](https://npm.io/package/@nos-sdk/nos-node-sdk.md) ^0.2.6

## Recent versions

- 3.0.7 (latest) — 2022-11-30
- 3.0.6 — 2022-09-05
- 3.0.5 — 2022-06-17
- 3.0.4 — 2022-05-19
- 3.0.3 — 2022-05-19
- 3.0.2 — 2022-05-19
- 3.0.1 — 2022-05-16
- 3.0.0 — 2022-05-16
- 2.2.2 — 2021-11-24
- 2.2.1 — 2021-09-01
- 2.2.0 — 2020-03-17
- 2.1.0 — 2019-09-23
- 2.0.4 — 2019-07-31
- 2.0.3 — 2019-06-13
- 2.0.2 — 2018-07-11
- … 4 more at https://npm.io/package/@winman-f2e/nos-upload/versions

## README

# nos-upload

## 配置说明
`host`及`endpoint`有三种配置方案：
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`

```javascript
// 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`注释

---
_Source: https://npm.io/package/@winman-f2e/nos-upload · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
