admin on rest send extra params to rest call

2020-04-15 11:04发布

i have upload button inside create form, on button click handler i will upload image to cloud and on upload success i get image url. i need to pass this image url to rest api. this is my sample code. When i submit my form i need to send image url as parameter. Can anyone help me.

Here is my code:

<SimpleForm label="Create Artist">
    <TextInput source="name" label="Name" />
    <FlatButton style={styles.button} label="Upload Image" primary onClick={this.handleClick} />
</SimpleForm>

this.handleClick = () => {
   cloudinary.openUploadWidget({
       cloud_name: 'demo',
       upload_preset: 'sh3432',
       cropping: 'server'
    }, function(error, result) {
       return result;
   });
};

1条回答
仙女界的扛把子
2楼-- · 2020-04-15 11:42

You'll have to implement a custom input for that.

Something like (haven't tested it):

class UploadPictureInput extends Component {
    handleClick = () => {
        cloudinary.openUploadWidget({
            cloud_name: 'demo',
            upload_preset: 'sh3432',
            cropping: 'server'
        }, (error, result) => {
            this.props.input.onChange(result);
        });
    }

    render() {
        return (
            <FlatButton
                style={styles.button}
                label="Upload Image"
                primary
                onClick={this.handleClick}
            />
        );
    }
}

And use this input in your form.

查看更多
登录 后发表回答