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;
});
};
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