@36node/upload
TypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published

@36node/upload

version downloads

a upload component that upload file to aliyun, support crop before upload and can integrate with antd form

Install

yarn add @36node/upload antd ali-oss

Usage

Simple

import Upload from "@36node/upload";
import "@36node/upload/dist/index.css";

const ossOptions = {
  endpoint: '<oss endpoint>',
  credentials: {
    accessKeyId: '<Your accessKeyId>',
    secretAccessKey: '<Your secretAccessKey>',
  }
  region: '<oss region>',
  bucket: '<Your bucket name>',
  url: '<oss prefix>'
}

<Upload ossOptions={ossOptions}>
  <Button>upload</Button>
</Upload>

Integrate With Form

<Form>
  <Form.Item>
    {getFieldDecorator("upload", {
      initialValue: [
        {
          uid: Date.now(),
          status: "done",
          name: "logo",
          url: "./images/logo.png",
        },
      ],
    })(
      <Upload ossOptions={ossOptions}>
        <Button>upload</Button>
      </Upload>
    )}
  </Form.Item>
</Form>

Crop Before Upload

check all crop options here

const cropOptions = {
  crop: {
    unit: "%",
    width: 100,
    aspect: 1,
  },
};

<Upload ossOptions={ossOptions} cropOptions={cropOptions}>
  <Button>upload</Button>
</Upload>;

check full examples here

API

@36node/upload is base on antd upload, it supports all antd upload api, check it here

some extra options are list below

Property Description Type Default
ossOptions aws-client-s3 options, required object -
cropOptions crop option from react-image-crop object -
maxFileSize the max size of file list. Size unit is kb. number -
maxFileNumber the max number of file list number -
value initial file list array -
onChange A callback function, can be executed when uploading state is changing Function -
listType Built-in stylesheets, support for three types: text, picture or picture-card String 'text'
accept File types that can be accepted. See input accept Attribute String -
preview Preview the uploaded pictures. If preview is true, the upload component will display preview of picture. Boolean true

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

module © 36node, Released under the MIT License.

Authored and maintained by 36node with help from contributors (list).

github.com/zzswang · GitHub @36node

Readme

Keywords

none

Package Sidebar

Install

npm i @36node/upload

Weekly Downloads

2

Version

0.5.0

License

MIT

Unpacked Size

543 kB

Total Files

9

Last publish

Collaborators

  • xuna08
  • zzswang
  • hauy
  • 36node-robot