mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 21:19:37 +08:00
64b905e9bd
* update icons deps * update all icon ref * fix lint * update snapshot
1.2 KiB
1.2 KiB
order | title | ||||
---|---|---|---|---|---|
10 |
|
zh-CN
使用 transformFile
转换上传的文件(例如添加水印)。
en-US
Use transformFile
for transform file before request such as add a watermark.
import { Upload, Button } from 'antd';
import { UploadOutlined } from '@ant-design/icons';
const props = {
action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
transformFile(file) {
return new Promise(resolve => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
const canvas = document.createElement('canvas');
const img = document.createElement('img');
img.src = reader.result;
img.onload = () => {
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
ctx.fillStyle = 'red';
ctx.textBaseline = 'middle';
ctx.fillText('Ant Design', 20, 20);
canvas.toBlob(resolve);
};
};
});
},
};
ReactDOM.render(
<div>
<Upload {...props}>
<Button>
<UploadOutlined /> Upload
</Button>
</Upload>
</div>,
mountNode,
);