@36node/upload
v0.5.0
Published
A module boilerplate for react component.
Downloads
51
Readme
@36node/upload
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
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- 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