通过使用upload组件来实现图片、视频等文件在七牛云的上传和删除?
一些代码:
this.state = {
previewVisible: false,
previewImage: '',
file:{},
fileList: [{uid: -1,
name: 'xxx.png',
status: 'done',
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
}],
token:""
}
}
handleCancel = () => this.setState({ previewVisible: false })
handlePreview = (file) => {
this.setState({
previewImage: file.url || file.thumbUrl,
previewVisible: true,
})
}
handleChange = ({ fileList }) =>{
this.setState({ fileList })
}
onRemove=(file)=>{
}
beforeUpload = (file)=>{
const isJPG = file.type === 'image/jpeg';
const isPNG = file.type === 'image/png';
const isGIF = file.type === 'image/gif';
if (!isJPG && !isPNG && !isGIF) {
message.error('格式不支持');
return false
}
const isLt2M = file.size / 1024 / 1024 < 2;
console.log(file.size);
if (!isLt2M) {
message.error('图片大小不能超过2MB!');
}
return isJPG && isLt2M || isPNG && isLt2M || isGIF && isLt2M ;
}
render(){
const { previewVisible, previewImage, fileList } = this.state
const uploadButton = (
<div>
<Icon type="plus" />
<div className="ant-upload-text">Upload</div>
</div>
);
const data={
token:this.state.token
}
写完之后实现的效果
我怎么可以更改七牛云上的文件名称?? 怎么获取到上传的地址??能不能进行拼接?
请各位大神多帮帮忙!!!谢谢了!!!
要改上传名称的话在data里加个key,url是七牛的前缀+response.key组成的