Image not being sent to NodeJS api from ReactJs redux-saga using yield call()

15 Views Asked by At

This is my saga function:-

// Sagas for Update Profile Starts //
function* updateProfileStartHandlerSaga(action){
    try
    {
        console.log(action.payload)
        const {data} = yield call(apiClient.post, '/api/v1/user/update-profile', action.payload)
        if(data?.success === true)
        {
            yield put({type : types.UPDATE_PROFILE_SUCCESS, payload : data})
        }
        else
        {
            yield put({type : types.UPDATE_PROFILE_ERROR, payload : data.message})
        }
    }
    catch(err)
    {
        yield put({type : types.UPDATE_PROFILE_ERROR, payload : err})
    }
}
export function* updateProfileStartWatcherSaga(){
    yield takeEvery(types.UPDATE_PROFILE_START, updateProfileStartHandlerSaga)
}
// Sagas for Update Profile Ends //

The loc console.log(action.payload) shows that the payload has the image data as well.

enter image description here

But when the request is made to the node js server, the image data is blank object. See the below screenshot.

enter image description here

I even tried to use formData, but still nothing happes.

try
{
    var formData = new FormData(action.payload);
    const {data} = yield call(apiClient.post, '/api/v1/user/update-profile', formData )
    if(data?.success === true)
    {
        yield put({type : types.UPDATE_PROFILE_SUCCESS, payload : data})
    }
    else
    {
        yield put({type : types.UPDATE_PROFILE_ERROR, payload : data.message})
    }
}

How can I fix this?

0

There are 0 best solutions below