React Admin The dataProvider returned an empty response for 'update'

Viewed 393

I'm creating a React Admin project with a Drf Api, the thing is, when I update the image field of one of my models, it updates, and everything works, but throws the next error: "The dataProvider returned an empty response for 'update'.".

I checked at the network section in the development tools, and it does receive a response from the api

Api response

Here is the React Admin data provider code:


const dataProvider = drfProvider('http://127.0.0.1:8000')

const myDataProvider = {
    ...dataProvider,
    update : (resource, params) => {
        if(!params.data.image) {
            return dataProvider.update(resource, params)
        }
        if (!params.data.image.rawFile) {
            delete params.data.image
            return dataProvider.update(resource, params)
        }
        return convertFileToBase64(params.data.image).then(image => {
            dataProvider.update(resource, { 
                ...params,
                data : {
                    ...params.data,
                    image : image
                }
            })
        })
    }
}

const convertFileToBase64 = file =>
    new Promise((resolve, reject) => {
        const reader = new FileReader();
        reader.onload = () => resolve(reader.result);
        reader.onerror = reject;

        reader.readAsDataURL(file.rawFile);
    });

export default myDataProvider; ```

1 Answers

While the thread is old, I came across this recently. Hope this helps somebody in future.

Currently the function isn't returning anything. Small change in the arrow function will ensure that the data is returned. I've removed the curly brackets after .then(image => {

return convertFileToBase64(params.data.image).then(image => 
            dataProvider.update(resource, { 
                ...params,
                data : {
                    ...params.data,
                    image : image
                }
            })
        )
Related