@51yzone/upload-sdk
TypeScript icon, indicating that this package has built-in type declarations

1.3.7 • Public • Published

统一请求库


基于 Taro 封装了文件上传功能,支持 Taro 跨端应用

何时使用

  • 上传文件到 oss 或自己的服务器

浏览器支持

Taro 跨端框架

API

UploadFile

upload

上传文件

安装

npm install @51yzone/request-extend --save

运行

# 默认开启服务器,地址为 :http://local:8000/

# 能在ie9+下浏览本站,修改代码后自动重新构建,且能在ie10+运行热更新,页面会自动刷新
npm run start

# 构建生产环境静态文件,用于发布文档
npm run site

代码演示

Taro

使用 AdapterTaro 实现 Taro 开发的小程序快速接入新后台规范

import RequestExtend, { AdapterTaro, ClientSdkBase, clientSetting } from '@51yzone/request-extend';
import UploadFile from '@51yzone/upload-sdk';
import { AtImagePicker } from 'rtaro-ui';
import Taro from '@rtarojs/taro';

const clientSDK = new ClientSdkBase(Taro);

const adapter = new AdapterTaro({
  clientSDK,
  headerDefault: { appId: '11' },
  clientSetting: clientSetting.alipayNew,
});
const requestExtend = new RequestExtend(
  {
    baseURL: 'https://community-test.51yzone.com',
  },
  adapter,
);

const uploadFile = new UploadFile(requestExtend, {
  uploadFile: Taro.uploadFile,
});

class App extends React.Component {
  constructor() {
    super();
    this.state = {
      fileList: [],
    };
  }

  onChange = files => {
    uploadFile.upload({
      uploadUrl: '/bizprod/common/image/rest/getOssSign',
      filePath: files[0].url,
      type: 'oss', //oss 上传阿里云 server上传服务器
      success: async res => {
        console.log('success');
      },
      fail: res => {
        console.log('fail');
      },
    });
  };

  render() {
    return <AtImagePicker multiple fileList={this.state.fileList} onChange={this.onChange} />;
  }
}
ReactDOM.render(<App />, mountNode);

Readme

Keywords

none

Package Sidebar

Install

npm i @51yzone/upload-sdk

Weekly Downloads

1

Version

1.3.7

License

MIT

Unpacked Size

32.5 kB

Total Files

19

Last publish

Collaborators

  • guxingke201
  • gpot
  • onemonmon