admin on rest send extra params to rest call

女生的网名这么多〃 提交于 2019-12-02 04:33:18

问题


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:


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.



来源:https://stackoverflow.com/questions/46377179/admin-on-rest-send-extra-params-to-rest-call

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!