marmot-client
TypeScript icon, indicating that this package has built-in type declarations

1.4.2 • Public • Published

调用 Marmot OpenAPI 客户端

例子 example

$ npm i -g ts-node
$ ts-node example/upload.ts

支持的接口

  • 查询应用信息
  • 上传文件
  • 调用异步任务
  • 加/解密

Publish

$ npm version patch
$ npm publish

upload

服务端一步上传

使用
import * as fs from 'fs';
import * as path from 'path';
import { MarmotClient } from 'marmot-client';

const client = new MarmotClient({
  accessKeyId: 'YOUR_ACCESS_KEY_ID',
  accessKeySecret: 'YOUR_ACCESS_KEY_SECRET',
  endpoint: 'http://kapi.marmot-cloud.com',
  apiVersion: '1.0.0',
});
// 1.1 上传公共文件,默认随机路径
async function uploadACLPublic() {
  const result = await client.upload({
    file: path.join(__dirname, 'sample.txt'),
    fileType: 'txt'
  });
  console.log('上传公共文件,默认随机路径', result);
}
参数
名称 类型 必填 默认值 样例 描述
fileType string txt 文件后缀名,需要和实际上传的文件类型一致
file string|Buffer|fs.ReadStream path.join(__dirname, 'sample.txt') 需要上传的文件
storagePath string my-sample.txt 可以自定义上传路径,默认上传到 uuid 随机路径
contentDisposition string 默认是文件名 attachment; filename=${encodeURIComponent('中文.xls')} 指定 Content-Disposition,例如 Content-Disposition: attachment; filename="filename.jpg" 点击链接下载文件而非打开文件
env string 不传默认是ak申请时默认的bucket DEV DEV DEV、TEST、PRE、PROD,申请AK时如果自定义存储服务时可以指定存储Bucket的环境标识,传入该字段可以对该租户下的bucket进行按env筛选出要上传的目标bucket
acl string public-read private private、public-read 标识返回的objectUrl是否是私有
... 阿里云或者aws扩展参数,会原封不动的传给阿里云或者aws
响应
名称 类型 样例 描述
objectUrl string http://cdn.marmot-cloud.com/storage/test-file-DEVELOPMENT/2022/07/08/4d33492e-7746-4d73-a747-f5fd27f28348.txt 上传后的文件地址
注意

一步上传的方式仅提供于纯服务端上传,如果你的应用有前端页面,我们强烈推荐你使用上述的两步接入的方法,需要 marmot-client 版本在 1.4.0 及以上才能使用。

Package Sidebar

Install

npm i marmot-client

Weekly Downloads

35

Version

1.4.2

License

none

Unpacked Size

32 kB

Total Files

10

Last publish

Collaborators

  • marmot.antgroup
  • xingxia
  • gxkl
  • zyhack
  • shaytang
  • kobe990